Archive

some Linux distributions are using a symlink-based method to manage multiple versions of the same binary. For example one could have several Java VM version installed on the same system. Usually typing the java command will start one of them … but which one? The command update-alternatives manages a set of symlinks, located in /etc/alternatives by default, which refer to the correct binary. In the case of java, /etc/alternatives/java will refer to the binary somewhere in /usr/lib/jvm (for Debian). To change this link just call:

The command’s output will show a list of installed alternatives for this binary, which will be configured by the packet manager. Selecting a number will change the symlink.

To add a custom alternative, update-alternatives –install is used. The description of this command can be found in it’s manpage, but I think an example will make it more clear. Let’s say we got JDK7 from the oracle website and want to add it. First install/copy it do a useful destination. I’ve chosen /usr/lib/jvm/java-7-sunjdk-amd64/jdk/. 😉

The first parameter (excluding –install) is the path of the symlink your system will use to find the binary. Therefore, it has to be at a location listed in your PATH environment variable. Thereafter, the name of the group is specified followed by the absolute location of the binary. A group is an alias which assorts the similar binaries. Finally, a priority value is set. The result looks like this:

update-alternatives –config java
There are 3 choices for the alternative java (providing /usr/bin/java).