How to prevent a Debian or Ubuntu package from being upgraded

Recently, I wanted to hold my virtualbox software at version 4.04 and prevent it from being upgraded.  If you use the gnome update-manager, you can always deselect the virtualbox  package in the GUI each time.  If you don’t like having to do that each time, I will show you two additional methods.  The first method using aptitude and the second method using dpkg/apt-get.  Choose one method or the other, the two methods are independent.

Method 1: Aptitude

Use aptitude to place a hold on a package and this will allow aptitude to upgrade everything else except packages that you have “held back”.

I’ll show you how to place a hold on the virtualbox package (virtualbox-4.0).

Start aptitude.

$ sudo aptitude

Your first action should always be to update your repo cache.  Hit the “u” key.

Next, search for virtualbox.  The “/” key will bring up a search box.  Enter virtualbox and hit enter.

If virtualbox is installed, aptitude should find it.

Hit the “=” key to place a hold on the virtualbox package.

You should see the flags “ih” now associated with the virtualbox package.  This means that virtualbox is installed and there is a hold placed on it.  It won’t be upgraded while it is held back.

Whenever you want to clear the hold flag, search and select the virtualbox package again and hit the “:” key.  That will remove the hold.

To upgrade your server.  Use the arrow keys to go to the top of the list and select the Upgradeable Packages.  Then hit the “g” key.

Hit the “q” key to quit aptitude.

Packages that are held back will still show in the Upgradable Package list whenever there are upgrades available for download.  If you try to upgrade it, it will be skipped.  As shown below.

If you prefer to use the cmdline, this is how to do everything that I just talked about, place a hold on virtualbox and upgrade everything (except virtualbox).

$ sudo aptitude update

$ sudo aptitude hold virtualbox-4.0

$ sudo aptitude safe-upgrade

And when you are ready to remove the “hold” placed previously on virtualbox and upgrade everything

$ sudo aptitude update

$ sudo aptitude keep virtualb0x-4.0

$ sudo aptitude safe-upgrade

Method 2: dpkg/apt-get

To place a hold on virtualbox and upgrade everything (except virtualbox).

$ sudo apt-get update

$ echo “virtualbox-4.0 hold” | sudo dpkg –set-selections

$ echo apt-get upgrade

To remove that hold on virtualbox and upgrade everything.

$ sudo apt-get update

$ echo “virtualbox-4.0 install” | sudo dpkg –set-selections

$ sudo apt-get upgrade

Summary

Whichever method you choose, please remember that each method is independent of the other.  In other words, if you use aptitude to place a hold on a package, then apt-get won’t see that hold.  If you place a hold using dpkg, then aptitude won’t see that hold either.   So remember to be consistent with whichever method you choose.  Yeah, it’s a bit nuts.

Advertisements

2 thoughts on “How to prevent a Debian or Ubuntu package from being upgraded

  1. In my experience “Hold” does not work well. I use apt-pinning instead, e.g. you create a file called /etc/apt/preferences and block a package from being installed specifying its name like this:

    Package: cups-client
    Pin: version *
    Pin-Priority: -100

    To block more packages just repeat the same block using different package names.

  2. sudo aptitude hold packagename
    sudo aptitude safe-upgrade

    These commands allowed me to upgrade while preventing google-chrome-stable from being downloaded and thus upgraded.

    later on : sudo aptitude keep google-chrome-stable

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s