How to exclude a package from Apt-Get upgrade in Ubuntu Linux. Learn how to prevent apt from updating of specific packages using the command line. During the normal update process, you will see that there are few packages that you do not want to upgrade but still it gets updated. Luckily there is a way to exclude a specific package from updating.
apt-mark
apt-mark can be used as a unified front-end to set various settings for a package, such as marking a package as being automatically/manually installed or changing dpkg selections such as hold, install, deinstall and purge which are respected e.g. by apt-get dselect-upgrade or aptitude.
format
apt-mark {hold | unhold | install | remove | purge} pkg… |
{showhold | showinstall | showremove | showpurge} [pkg…]
hold
hold is used to mark a package as held back, which will prevent the package from being automatically installed, upgraded or removed.
unhold
unhold is used to cancel a previously set hold on a package to allow all actions again.
showhold
showhold is used to print a list of packages on hold in the same way as for the other show commands.
Exclude A Package from Apt-Get Upgrade
As the packages can be updated using apt, dpkg or aptitude, there are three ways to exclude a specific package from Apt-Get upgrade process.
The apt-mark command can be used with apt, dpkg or aptitude. See below for the respective command format:
$ sudo apt-mark hold package_name
$ echo "package_name hold" | sudo dpkg --set-selections
$ sudo aptitude hold package_name
Change the package_name with your actual package name to be set on hold.
List All Packages That Are On Hold
dpkg –get-selections shows packages marked “deinstall”. This is the simplest way to list all the packages that are put on hold for update process. Simply run the following command:
$ dpkg --get-selections