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.