There are multiple ways of preventing a package from updating in Debian, Ubuntu, Linux Mint, elementary OS and other Debian/Ubuntu-based Linux distributions. This article presents 3 ways of excluding repository packages from being upgraded.
Why prevent a package from being updated? Let's say you install a package that's older than the version available in Debian, Ubuntu or Linux Mint repositories, or you know some update is causing issues, and you want to upgrade all packages minus one (or two, three...).
Here's an example. I'm using Chromium browser with hardware accelerationpatches from the Saiarcot895-dev PPA, in Ubuntu 18.10. To get hardware acceleration to work with Nvidia drivers, a patched vdpau-va-driver package is needed, and this is not yet available in this PPA for the latest Ubuntu 18.10. Luckily, the Ubuntu 18.04 package can be installed in Ubuntu 18.10, but any upgrade through "apt upgrade" or using the Software Updater will upgrade this package, which I don't want. So in this case, holding this package from upgrades would allow me to upgrade all other packages without having to worry about it.
It should be noted that preventing a package from future upgrades may cause issues in some situations, if the package you're holding is used as a dependency for another package that can be upgraded. So try not to prevent too many packages from upgrades, especially libraries.
Here are 3 ways of preventing a package from updating in Debian, Ubuntu, Linux Mint.
1. Prevent package updates using a GUI: Synaptic Package Manager
Synaptic Package Manager, a Gtk graphical package management program for apt, can lock packages which prevents them from being updated.
It's important to note that using Synaptic to lock packages won't keep them from being updated from the command line - running
apt upgrade or
apt-get upgrade will still upgrade a package locked in Synaptic. Locking packages in Synaptic will prevent package upgrades using Ubuntu's Software Updater app, and possibly other graphical package managers. It will not prevent updating packages using the Linux Mint Update Manager application though. As a result, I recommend using
dpkg (see below) to keep packages from updating.
You can install Synaptic Package Manager using this command:
sudo apt install synaptic
To prevent a package from updating using Synaptic, search for it, select the package and from the Synaptic menu click
Package -> Lock Version:
In the same way you can unlock the package too.
To see all locked packages in Synaptic, click
Status in the bottom left-hand side, then click on
Pinned above the
2. Keep a package from updating using
Holding packages from updating with apt-mark should prevent them from updating using Ubuntu's Software Updater, as well as command line upgrades (
apt upgrade /
You can hold a package from future upgrades (and from being automatically removed) with
apt-mark by using this command:
sudo apt-mark hold PACKAGE
PACKAGE with the package you want to hold from updating.
You can check which packages marked as
hold by using:
To remove a hold (so the package can be updated), use:
sudo apt-mark unhold PACKAGE
unhold you can specify multiple packages, just like when installing software with
apt (separate the packages by a space).
3. Prevent package updates with
A while back there were some graphical package managers that ignored the apt-mark hold status. I'm not sure if that's still the case, but just to be safe (and in case you're using an old Debian / Ubuntu / Linux Mint version), here's another way of preventing package updates in Ubuntu, Linux Mint or Debian: dpkg.
To prevent a package from upgrades using dpkg, use:
echo "PACKAGE hold" | sudo dpkg --set-selections
You can see all package holds using this command:
dpkg --get-selections | grep hold
To remove the hold (allow the package to be upgraded), use:
echo "PACKAGE install" | sudo dpkg --set-selections
apt-mark, this solution doesn't allow specifying multiple packages at once.