How to hold or lock Packages in Ubuntu

This brief tutorial shows students and new users how to setup Ubuntu to hold or prevent packages from updating.

In some cases you may not want to update a particular package. For instance, you have a Nginx web server configured with specific settings and you know updating will change its configuration and stop it from working.

You can setup a package hold so that it won’t be updated even when updates are available until you’re ready to update it.

Preventing a package from being installed or updated is known as “package holding“.

This is a great feature in that you’re not automatically bound to update a package or software you don’t want to update in the meantime. You can also update at a later date.

To get started with locking or holding packages in Ubuntu, follow the steps below:

Show held packages

There are many tools available to lock or prevent packages from updating. You can install and use Synaptic package management, Aptitude to hold packages or use the command to do the same.

Using the command line, to show all packages that are being held back from updates, run the commands below:

sudo apt-mark showhold

That will list packages that are on hold.

Hold or lock packages

Now that you know how to show locked packages, use the commands below to lock or prevent specific packages from updating.

sudo apt-mark hold <package-name>

If using aptitude, use the commands below:

sudo aptitude hold <package-name>

Replace <package-name> with the package you want to hold back. For example if you want to hold back Nginx web server, run the commands below:

sudo apt-mark hold nginx

That will hold back Nginx web server from updating.

Unlock packages

If you want to unfreeze or unlock packages and have them continue to get updates, run the commands below:

sudo apt-mark unhold <package-name>

If you’re using aptitude, run the commands below:

sudo aptitude unhold <package-name>

Again, replace <package-name> with the package you want to unlock or unfreeze and have them continue to get updates.

For example, if you want to unlock Nginx after you locked above, run the commands below:

sudo apt-mark unhold nginx

Synaptic package management

If you are using Synaptic package management, then go to Synaptic Package Manager (Activities ==> Search for Synaptic).

Click the search button and type the package name you want to lock.

When you find the package, select it and go to the Package menu and select Lock Version.

That will lock the package from receiving updates.

That should do it!

Conclusion:

This post showed you how to setup Ubuntu to lock packages and prevent them from installing or receiving updates.

If you find any error above, please use the form below to report.

You may also like the post below:

How to Watch Netflix on Ubuntu | Website for Students

One Reply to “How to hold or lock Packages in Ubuntu”

  1. Also of note:
    If you have a package you are actively using, and don’t want it removed|auto-removed;
    then holding a package works there to.
    In my case my system wanted to remove tmux, b/c it was a dependency of byobu;
    but I’ve switched to just tmux since then.
    I should probably un-hold & re-install, but I’ll do that when I don’t have multiple sessions going.

Leave a Reply

Your email address will not be published. Required fields are marked *

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