The Debian Project

previous | Contents | 1 | 2 | 3 | | 5 | 6 | 7 | 8 | 9 | next

The Debian Maintenance HOWTO
Chapter 4 - Alternatives

Debian has developed a mechanism that will provide you with an interface to install several packages that provide the same functionality. For example take the program vi. There is not a single vi package but half a dozen of them. All can be installed to provide /usr/bin/vi, the admin decides which of them will actually provide this common interface.

This is achieved by making /usr/bin/vi a symbolic link to /etc/alternatives/vi. That file again is a link, which gets automatically created, to the real binary. Along with the program there is a so called slave-link for the manpage.

This mechanism is controlled by the update-alternatives program. It creates, removes, maintains and displays information about the symbolic links comprising the Debian alternatives system. For each major link (contrary to a slave-link) can be configured with a priority which will control which package actually provides the second link.

4.1 Display Alternatives

to find out which alternatives exist on your system, you have to list the directory contents of /etc/alternatives. You'll find a lot of links in there. Some of them are slave links that you can ignore for the following actions. Slave links are often manpages, thus the links foo.1.gz.

If you know the link name you can issue a direct query to the system by using update-alternative --display vi. The name vi is just a common example. The program will display all affected packages and also display the choosen one.

4.2 Configure Alternative

The program update-alternative provides a simple but sufficient configuration frontend. Simply call it as update-alternatives --config foo where foo is a major link from /etc/alternatives.

4.3 Add Alternative

A new alternative is set with --install as argument to update-alternatives. Each alternative has a priority that controls the creation of the link. The higher the priority the more probably this alternative will be used. Since you can change an alternative by re-installing it you can also change the priority at the same time. As an example, the following code forces vi to be a link to vim (using priority 900). For details please refer to the manpage for that program.

       update-alternatives --install /usr/bin/vi vi /usr/bin/vim 900 \
        --slave /usr/share/man/vi.1.gz vi.1.gz /usr/share/man/vim.1.gz

4.4 Remove Alternative

An alternative is removed with:

       update-alternatives --remove vi /usr/bin/vim

The Debian Maintenance HOWTO

November 23rd, 2014

Joey Schulze, joey@infodrom.org