Translation(s): English - Italiano - Русский


Debian Alternatives System

The Debian alternatives system creates a way for several programs that fulfill the same or similar functions to be listed as alternative implementations that are installed simultaneously but with one particular implementation designated as the default. For example many systems have several text editors installed at the same time. The vi program is a classic example of an editor that has many implementations such as nvi, elvis, vim, etc. but which one should be designated as the default?

Debian's alternatives system aims to solve the problem of selecting a default preferred version. Management is done through the update-alternatives program that creates, removes, maintains and displays information about the symbolic links constituting the Debian alternatives system. Priorities are assigned by package creators. The alternative with the highest priority determines the default value when in automatic mode. Additionally the local administrator may override the automatic selection with a manual selection.

The Debian alternatives system was originally created for Debian but has been picked up by other GNU/Linux software distributions. For example Red Hat now uses a fork of the code to maintain system software such as /usr/sbin/sendmail. On RHEL/Fedora /usr/sbin/sendmail is an alternatives symlink to either the classic Sendmail or to Postfix as alternative implementations of an MTA. In fact the alternative group is called the mta group there.

Here is a previous rant on the subject in the debian-user mailing list that I think is a good introduction to using the Debian alternatives system. I will eventually pull most of that discussion into this wiki page but for now I will just reference it.

One-Liners to manipulate alternatives

Here is a long one-liner that will print out all manually configured Debian Alternatives symlinks.

for i in /etc/alternatives/*; do 
  LANG=C update-alternatives --display "${i#/etc/alternatives/}"
done 2>/dev/null | awk '/manual.mode/{print $1}'

If all of those are something that you want to reset to automatic then this can be done using the same generated list. Otherwise simply grep out the ones that you want or don't want.

for i in /etc/alternatives/*; do
  LANG=C update-alternatives --display "${i#/etc/alternatives/}"
done 2>/dev/null |
  awk '/manual.mode/{print $1}' | 
  xargs -L 1 sudo update-alternatives --auto

See Also