Raven - Blog
April 4, 2022

Debian - Blocking package modifications

Posted on April 4, 2022  •  2 minutes  • 322 words  • Other languages:  Français

When you install a package, it comes with its dependencies automatically. Then when you upgrade your distribution, some packages (and especially dependencies) can be removed if they are not needed anymore for example.

In some cases it may be important to block the upgrade of a specific package or to prevent it from being removed during an apt-get autoremove or other upgrade.

apt-mark method:

The apt-mark command allows you to mark a package in different ways, here are some sample options:

When installing package A, dependencies B, C and D are installed. Package A will be marked as “manual” by apt and packages B, C and D will be marked “auto”. The day you uninstall package A, packages B, C and D will be uninstalled automatically (unless they are the dependency of another package). Let’s say you want to keep package C even after removing A, just mark it as “manual” with :

1
apt-mark manual paquetC

In another case, you want package A to never be updated automatically. Its version is very important to you and you want to control when it is updated. To do this, you can prevent it from being upgraded or removed by an automatic process like apt-get upgrade with :

1
2
apt-mark hold nondupaquet
apt-mark showhold

The showhold option will show you the list of selected packages.

However, be careful not to abuse this method too much, you will end up with dependency and security problems sooner or later.

Alternative method

You can do the same thing with the wonderful dpkg of course!

1
echo "nom_du_paquet hold" | dpkg --set-selections

Here you go!

To unlock a package:

1
echo "nom_du_paquet install" | dpkg --set-selections

To get the list of blocked packages :

1
dpkg --get-selections | grep hold
Follow me

Subscribe to my RSS feed !