How to prevent apt from updating of specific packages

I normally use apt-get or aptitude to upgrade my system to the latest version. Is it possible to upgrade all packages except a given one?
As we know, we can easily prevent updating of a certain package in CentOS/RHEL, we can for sure do that in Debian/Ubuntu, but it’s slightly different.

In order to prevent a package from auto upgrading in Ubuntu/Debian, we need to put the package in hold mode. There are four ways of holding back packages, with dpkg, apt, aptitude, or with dselect.

Way 1: Using dpkg
Put a package on hold, and prevent from upgrading.

echo "package_name hold" | sudo dpkg --set-selections

Remove the hold, and enable upgrading

echo "package_name install" | sudo dpkg --set-selections

Displaying the status of your packages

dpkg --get-selections

Displaying the status of a single package

dpkg --get-selections | grep "package_name"

Way 2: Using apt
hold a package using

sudo apt-mark hold package_name

and remove the hold with

sudo apt-mark unhold package_name

Way 3: Using aptitude
hold a package like,

sudo aptitude hold package_name

and remove the hold with

sudo aptitude unhold package_name

Way 4: Using dselect
With dselect, you just have to enter the [S]elect screen, find the package you wish to hold in its present state, and press = or H. The changes will go live immediately after you exit the [S]elect screen.

Share Button

Leave a comment

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