Linux basics : alternatives system

The alternatives system is used (on red hat and similar distro's ) to automatically maintain symbolic links to binary files on a priority based system.

For example:

/usr/bin/java - > /etc/alternatives/java -> /path-to-binary-files

This configuration adds a layer of abstraction so you can update, switch versions, and/or switch vendors with out breaking applications.

Want to switch to a newer version of java, yet do not want to remove or relocate your existing java, then this is your answer.

To see a list of alternatives for a given link group, you can use the --display option.

sudo /usr/sbin/alternatives --config java

output :

There are 2 programs which provide 'java'.

Selection Command-----------------------------------------------

* 1 /usr/lib/jvm/jre-1.4.2-gcj/bin/java

+ 2 /usr/java/jdk1.6.0_24/bin/java

Enter to keep the current selection[+], or type selection number:

When you install a new binary file via RPM it gets listed here with a default priority. So you can go ahead to install a new java version then just modify the alternatives. Want to roll back to an older version ? that's done easily.

Note : for configuring the jdk, you need to configure both java and javac with the alternatives system.

And here comes the real reason i'm writing this post.

I installed a new java rpm , but its not listed in the alternatives list. What do i do ?

If not picked up automatically by alternatives, you can manually register it as follows

sudo /usr/sbin/alternatives --install "/usr/bin/java" "java" "/usr/java/jdk1.6.0_24/bin/java" 1

sudo /usr/sbin/alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk1.6.0_24/bin/javac" 1

Then go ahead and select it from the alternatives list.