APT: Prevent upgrading of particular packages
There are cases in which it is desirable to keep a certain package version, be it a forced downgrade or a custom build. Here I show several ways to achieve this.
The most simple possibility is to mark the package hold in the dpkg
status file /var/lib/dpkg/status
:
$ echo "PACKAGE_NAME hold" | dpkg set-selections
or, using apt-mark
as wrapper:
$ apt-mark hold PACKAGE_NAME
To undo this and return the selected package to apt
's default workflow, run
$ echo "PACKAGE_NAME installed" | dpkg set-selections
or, respectively:
$ apt-mark unhold PACKAGE_NAME
This is a very static solution and apt
provides a much more flexible way of package handling, called pinning. It is configured in the file /etc/apt/preferences
resp. in an arbitrary file in the /etc/apt/preferences.d/
directory.
Pinnig allows prioritization of package versions depending on factors like version number, repository or release name - wildcards and regular expressions are allowed. The most simple configuration for a single package, analog to the dpkg
way described above, would look like this:
### File: /etc/apt/preferences
### OR
### /etc/apt/preferences.d/SOMEFILE
Package: PACKAGE_NAME
Pin: version PACKAGE_VERSION
Pin-Priority: 1001
See the manpage apt_preferences(5)
for a detailed description of all pinning possibilities.
Finally, for local builds it is possible to assign them a local version number, as I have described in this post, and pin, if necessary, based on that.