This site is now 100% read-only, and retired.

Using the Debian alternatives system

Posted by Steve on Fri 11 Feb 2005 at 22:40

Debian is the single largest GNU/Linux distribution around, with more developers, more supported platforms and more packages than any other. With so many choices it's often the case that people will have differing ideas about the tools to use - such as text editors. The Debian alternatives system attempts to solve this problem.

There are many examples of a program having to invoke another one by name - for example many programs will need to allow the user to make changes to a file. So they must run a text editor, but which one? It's not appropriate for Debian to mandate the use of a particular tool to do a particular job, if there are several alternatives available.

For example when scheduling commands with Cron you will be presented with an editor to make changes to the crontab file.

Rather than the cron package forcing the use of a particular editor it will allow you to specify the editor to use via the environmental variable EDITOR. Using environmental variables like this is fairly common in the Unix world, as it allows each program to offer the user a choice.

However Debian has a different solution to the problem.

For some special classes of applications which have many programs that can be used, Debian allows you to choose which particular alternative you wish to be used, globally. This covers a set of programs such as:

  • Text editors
  • Web browser
  • Window managers

The way it works is to have a set of standard command names such as editor, www-browser, and view. Each of those commands are merely symobilic links to the real command.

For example assume you have both the vim and emacs21 packages installed. To handle this a program that wishes to allow you to edit a file merely runs:


This is a symbolic link which links to:


This in turn links to the real editor, either vim or emacs in our example.

This extra level of indirection allows you to easily update the system to execute the editor you prefer. You could update the symbolic links by hand, but the preferred approach is to run:

update-alternatives --set editor /usr/bin/emacs21

This will set the symbolic link in the directory /etc/alternatives to point to the emacs binary - so now whenever a command runs "editor" emacs will be invoked.

If you wish to change your mind, and use vim in the future you merely need to run:

update-alternatives --set editor /usr/bin/vim

This will cause vim to be executed whenever you run "editor".

The command has several useful options which you can find discussed in the manpage, view that by running:

man update-alternatives

For example you can see which "real" program will be executed for a given name:

skx@lappy:~$ update-alternatives --list x-www-browser

This shows us that executing the command "x-www-browser" will end up executing mozilla-firefox, on your machine something completely different could be executed!



Posted by Anonymous (62.253.xx.xx) on Mon 14 Feb 2005 at 14:18
galternatives is, to my mind at least, an excellent graphical front-end to the alternatives system. The only place I can find with pretty pictures of it is its Debian developer's page. Well worth installing!

[ Parent ]

Re: galternatives
Posted by glanz (216.209.xx.xx) on Sun 20 Feb 2005 at 15:44
[ View Weblogs ]
Fantastic! I was not aware of that application..... ThanX for the new toy!(^> /v) ~~

[ Parent ]

Polish translation
Posted by ptecza (83.24.xx.xx) on Tue 10 May 2005 at 22:06
Hi Steve!

I've also translated your next article to Polish [1].
Thank you very much for it and ask for more :)

Best regards!


[1] -

[ Parent ]

Using Debian alternatives to set default desktop
Posted by boog (83.214.xx.xx) on Thu 18 Aug 2005 at 23:23
A recent upgrade of testing left my previously KDE box booting to console. "startx" would only launch XFCE4. It wasn't obvious how to change this behaviour. The trail of X startup scripts is pretty long and complicated (to a relative beginnner), but in the end I discovered that the Debian solution was simple: type

# update-alternatives --config x-session-manager

and enter the number of the desired option in the list displayed (1 for KDE). Easy when you know how. Note that this is the system wide default.

[ Parent ]

Re: Using the Debian alternatives system
Posted by JohnMG (69.177.xx.xx) on Tue 1 Nov 2005 at 20:51
Looking in /etc/alternatives, I see that, besides using this system for multiple apps that all do the same thing (i.e. editor-->"/usr/bin/vim"), it also seems to be used for:

- cases where you've got a common name referring to specific name (like emacs-->/usr/bin/emacs20)

- cases where an older style name refers to the modern equivalent (maybe cc-->/usr/bin/gcc or csh-->/usr/bin/tcsh or rcp-->/usr/bin/scp)

- cases where a Unix-style name refers to the modern GNU equivalent (like yacc-->/usr/bin/bison)

[ Parent ]

Re: Using the Debian alternatives system
Posted by Anonymous (62.23.xx.xx) on Mon 24 Apr 2006 at 14:43
Hi there, great article, i knew the basics but wasn't aware of the update-alternatives command :-)

I've made a french translation here:

hope it helps

[ Parent ]