Deb: preventing packages from updates

From lxadm | Linux administration tips, tutorials, HOWTOs and articles
Jump to: navigation, search

Sometimes, you may want to prevent a certain deb package from updating, i.e. when running apt-get upgrade or apt-get dist-upgrade.

For example, to leave redis-server package not updated, you would first run (make sure to run as root, or with sudo):

# echo "redis-server hold" | dpkg --set-selections  


Then, when you run apt-get dist-upgrade, you would see that redis-server (and a related package, redis-tools) were kept-back:

(...)
Calculating upgrade... Done
The following NEW packages will be installed
  linux-headers-3.16.0-77 linux-headers-3.16.0-77-generic
  linux-image-3.16.0-77-generic linux-image-extra-3.16.0-77-generic
The following packages have been kept back:
  redis-server redis-tools
The following packages will be upgraded:
  apparmor apport apt apt-transport-https apt-utils base-files bash-completion
  bind9-host binutils biosdevname bsdutils ca-certificates coreutils cpio
(...)


To list the packages put on hold, do:

# dpkg --get-selections|grep hold
redis-server                                    hold


Or, for a given package/packages:

# dpkg --get-selections|grep redis
redis-server                                    hold
redis-tools                                     install


To remove the hold, do:

# echo "redis-server install" | dpkg --set-selections


If you're using a newer tool, apt, you can do this one to hold the package:

# apt-mark hold redis-server


And this one, to remove from hold:

# apt-mark unhold redis-server