There are many things you can do in Linux and there are many ways to do them. You can have several different programs all able to do the same task and all installed at the same time. So how do you choose which one is the default program?
As an example lets compare text editors. Many programs call a default text editor when you wish to edit some text (duh!). By default Debian based systems use nano as their text editor. But perhaps you are more comfortable with vim or (shudder) emacs. Perhaps you are a real die hard Linux geek hero and get down and dirty with ed (not the talking horse, of course).
Another classic example is java. There are several different java implementations and they can all be installed at the same time. Yet when your web browser calls for a java interpreter only one is called. It doesn't matter if you are using Firefox, konqueror or dillo. They all start up the same version of java.
So how do these programs know which default program to call when they wish to perform an outside function? Well the Debian based distributions use a program called update-alternatives and it is part of the dpkg package. Here is part of what "man update-alternatives" states:-
Debian’s alternatives system aims to solve this problem. A generic name in the file system is shared by all files providing interchangeable functionality. The alternatives system and the system administrator together determine which actual file is referenced by this generic name. For example, if the text editors ed(1) and nvi(1) are both installed on the system, the alternatives system will cause the generic name /usr/bin/editor to refer to /usr/bin/nvi by default. The system administrator can override this and cause it to refer to /usr/bin/ed instead, and the alternatives system will not alter this setting until explicitly requested to do so.
So taking our java installation(s) lets see how this works. First lets find the java program.
locutus@borgmothership:~$ which java
/usr/bin/java
Well that is what we expected. Lets look closer.
locutus@borgmothership:~$ ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 2007-12-11 16:49 /usr/bin/java -> /etc/alternatives/java
Hmmm interesting. Lets examine that.
locutus@borgmothership:~$ ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 36 2008-11-24 09:45 /etc/alternatives/java -> /usr/lib/jvm/java-6-sun/jre/bin/java
Ah hah! We have found out that by calling the generic program "java" we are actually calling the sixth version of java as produced by sun. (MMmmmm, sun dried java). Fine but why go through all the rigmarole of linking links like a chain? Here's why.
There can be several versions of java installed and why bother our heads trying to keep track of them all when the computer can do that work for us.
locutus@borgmothership:~$ update-alternatives --list java
/usr/lib/jvm/java-6-sun/jre/bin/java
/usr/lib/jvm/java-1.5.0-sun/jre/bin/java
/usr/bin/gij-4.2
Cool. Now lets say I don't wish to use sun's java at all. I fix this by the following command.
locutus@borgmothership:~$ update-alternatives --set java /usr/bin/gij-4.2
Using '/usr/bin/gij-4.2' to provide 'java'.
That is all there is to it. No need to fiddle around with link commands and trying to remember what is on second and who's on first. Remember, the purpose of computers is to make our life easier.
Incidentally it is also what the dpkg triggers use to set default programs when you install packages. If you wish to check out all of your default programs and change them at will then you can simply type "update-alternatives --all". Read man update-alternatives for more info.
- Locutus's blog
- Add new comment
- 3518 reads

There are many things you can
There are many things you can do in Linux and there are many ways to do them. You can have several different programs all able to do the same task and all installed at the same time. So how do you choose which one is the default program? As an example lets compare text editors. Many programs call a default text editor when you wish to edit some text (duh!). By default Debian based systems use nano as their text editor. So how do these programs know which default program to call when they wish to perform an outside function?
Galternatives
there is a program in the Ubuntu repo called "galternatives" that can make the process of selecting an alternative easier. I can't figure out how to use it to create an alternative (i.e. for two manually installed versions of a program) but for all other uses its great.
Galternatives
there is a program in the Ubuntu repo called "galternatives" that can make the process of selecting an alternative easier. I can't figure out how to use it to create an alternative (i.e. for two manually installed versions of a program) but for all other uses its great.
Love the site
Nice new place you got here.
Thank you
If there is anything you would like to be improved upon feel free to make suggestions.