Home Command line utilities 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

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

By sk
397 Views

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 anyone want to do that. There could be many reasons. A particular version of a package is just working fine, so you simply don't want to update it to the latest version. Sometimes, the updated packages might have some issues. Even though the developers tests 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 500 MB. So that you can simply hold it back from being upgraded. These are a few 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 that package.

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 after 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 will not prevent the package from 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, even if a new version is available. 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.

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

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

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

Conclusion

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.

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

2 comments

Giovanni April 18, 2018 - 9:25 pm

Just a comment: I believe the command to unhold the package htop is without the hyphen

sudo apt-mark unhold htop

Reply
sk August 4, 2018 - 1:00 pm

Yeah, you’re right. Corrected now. Thank you.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More