How to prevent a package from being automatically installed, upgraded or removed in Ubuntu

prevent a package from being automatically installed, upgraded or removed in Ubuntu

Today, I came across an important and useful tip for Debian, Ubuntu distros, and wanted to share it with our readers. In this brief tutorial, we will see how to prevent a package from being automatically installed, upgraded or removed. Some of you might wonder why would someone want to do that. There could be many reasons. You are happy with particular version of a package, and you don’t want to to waste your time by updating a package to the latest version which is unnecessary or not that important to you. Please be careful that sometimes the outdated packages might be vulnerable and cause security issues. In such cases, you must update it to the latest version. If you are don’t care about the security, just keep it outdated as long as you you want.

The updated packages might be problematic. Of course, the developers will test the packages thoroughly before pushing them into the repositories. But sometimes they might push unstable, and problematic packages unknowingly which will eventually damage our systems. You just want to save a bandwidth. Say for example, you don’t want to update a package that consumes more than 300 MB. So that you can simply hold it back from being upgraded. These are some reasons that I find to prevent a package from updating. The reasons might be different and vary for you. Whatever it is , if you want to hold a package go on and find out yourself.

We can lock the package either in Command line (using apt-get) or graphical way (using Synaptic package manager). Both are easy to follow.

The command line way (Using apt-get)

To lock a package from being automatically installed, updated, or removed, we can use ‘apt-mark’ command. This command has many options. You can read the man pages for details about each option.

man apt-mark

In this tutorial, We will use two options namely hold and unhold.

  1. hold – block any package from being installed, updated, upgraded, or removed.
  2. unhold – Release the package from hold, and allow us to install, update, remove packages.

Let us mark (hold) a package, for example htop, as shown below.

sudo apt-mark hold htop

Sample output:

htop set on hold.

And that is all, the version currently installed at the time of the lock will stay installed even during upgrades. It is very useful while holding back graphics drivers.

To unhold the package, just run:

sudo apt-mark-unhold htop

Sample output:

Canceled hold on htop.

Important: Please note that this method doesn’t opt for manual removal. You can still remove the locked packages using “apt-get remove <packagename>” command. Do not assume that the marked packages can not be removed.

This method only prevents the application from automatically installed, updated, upgraded, or removed during system upgrade. Holding a package actually means you’re telling the package manager to keep the current version no matter what. This is useful if more recent version of a currently working program breaks after an update.

Whenever you try to update the system using commands “sudo apt-get update” or “sudo apt-get upgrade”, the marked packages will still be the same version at the time you hold the package.

You might also want to check our compliment guide for more command line help.

The graphical way (Using Synaptic package manager)

If you have Synaptic package manager installed on your system, you can easily lock a package from being installed, updated, upgraded, or removed.

To do so, Open Synaptic manager either from Unity dash or Menu. Search the package you want to hold. Then go to Package from the menu bar and click hold.

That’s it. Now, the package will not be touched during system upgrade as long as you kept it in hold.

If Synaptic package manager is not installed in your system, you can install it using command:

sudo apt-get install synaptic


We have learned how to prevent a package from being installed, updated or removed during system update. It is a good practice if you find out a recent version of a particular package is not stable or break the system. You can simply hold the packages using ‘apt-mark’ command, so that the package managers won’t touch the package as long as you hold them back.

That’s all for now. I will be here with another interesting article soon. Until then stay tuned with OSTechNix.


Thanks for stopping by!

How can I benefit from this blog:

Have a Good day!!

You may also like...