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

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 might happy with the particular version of a package, and don’t want to waste time by updating it to the latest version which is unnecessary. Sometimes, the updated packages might be problematic. Even though the developers will test the packages thoroughly before pushing them into the repositories, sometimes they might push unstable, and problematic packages unknowingly which will eventually damage our systems.

Sometimes, you will just want to save the 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 can say 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, this tutorial will help you to do so.

Note: Please be mindful that holding back packages from being upgraded is not recommenced in production. 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 the packages outdated as long as you you want.

Prevent A Package From Being Automatically Installed, Upgraded Or Removed In Ubuntu

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

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

For the purpose of this guide, We will discuss only 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.

The locked package will remain as the same version even if you upgraded your system. This trick can be 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.

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 as described below.

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


You know now how to prevent a package from being installed, updated or removed during system update in Ubuntu. It is a good practice to follow when you find out the 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 unhold 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...