Introduction

There's a rather interesting feature about Debian that many people don't know about. Debian is able to handle "groups" of similar applications. It's installed by default (part of the base-system in fact) and is quite often used by the post-configuration of installed packages.

How does it work?

The alternatives for a program are listed in /etc/alternatives. While these are not to be removed manually, this directory holds symlinks for each application that has an alternative. This includes symlinks to the binary itself, and to any relevant manpages that might exist for it.

Displaying the status of a program

Let's take an example. The base-system of any Debian install has nvi installed which is a small binary of vi found on many BSD systems. While that's all well and good, let us assume that you installed vim. Normally, vi's update preferences are managed automatically, but we can see how by doing:

[[n6tadam@station|n6tadam]]$ sudo update-alternatives --display vi

vi - status is auto.
{{{
 link currently points to /usr/bin/vim
/usr/bin/nvi - priority 30
 slave vi.1.gz: /usr/share/man/man1/nvi.1.gz
/usr/bin/vim - priority 120
 slave vi.1.gz: /usr/share/man/man1/vim.1.gz
Current `best' version is /usr/bin/vim.

}}}

I've used sudo here, because I have it installed, however this command needs to be run as the "root" user, otherwise.

You'll notice that it says that the status for vi is set to auto. This means that the package will decide which vi is best to use. This is handled by the priority of the application. Since vim has a priority of 120, and nvi only has a priority of 30, vim takes precedence.

Configuring alternatives

But what if you didn't want the command vi to run vim but you wanted it to run nvi instead? The following will allow you to change it:

[[n6tadam@station|n6tadam]]$ sudo update-alternatives --config vi
{{{
                                                                                
There are 2 alternatives which provide `vi'.
                                                                                
  Selection    Alternative
-----------------------------------------------
      1        /usr/bin/nvi
 * +    2        /usr/bin/vim
 
Press enter to keep the default[*], or type selection number:

}}}

Here, I would press "1", which would then link vi (and any relevant manpages) to nvi. Since this is a manual update of alternatives, if I then installed another application in the same group (elvis for example) then this would not override anything. If i wanted to put it back, or to allow the system to update the alternatives for me, I can do:

[[n6tadam@station|n6tadam]]$ sudo update-alternatives --auto vi

There are also some really other good uses. You can update the alternatives for "x-window-system" and "x-session-manager". This has been just a brief look at alternatives. The man page (man update-alternatives) has many more options and explanations.


This page was written by: ThomasAdam

LinuxHints/UpdateAlternatives (last edited 2005-02-17 00:23:55 by 216)