Thursday, May 16, 2013

Upgrading Java

When ever you upgrade Java, the old version is always left on the server and is still in use. You will have to do the following to activate and use the new version.
in this example I am upgrading from Java 1.4 to 1.6
if java is available in your repository type 
yum update java or if you have the rpm
type rpm -Uvh java-version_of_yourJava.i386.rpm 
Although upgrade option is used in both instances, java is not actually upgraded. Just the new version is  installed alongside your current version.

You need to use the alternatives system to use the new version. here's how. type alternatives --config java 
The alternatives system maintains symbolic links determining default commands. Our new version of java is installed under
 /usr/java/jdk1.6.0_26 (so the path of java binary is /usr/java/jdk1.6.0_26/bin/java. I’ll add this as the default for Java:

type 

alternatives --config java 
You should receive output similar to the following:


There is 1 program which provide 'java'.

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

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


As you can see the new version of Java is not only not being used, but there is no mention of it in the alternatives system.
So we need to add it to the alternatives system to be able to use it. heres how. type 
alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_43/bin/java 1 

The syntax of alternatives is as following 
-- install /path_to_symlink program_name /path_to_program priority

Once done if you type
alternatives --config java 
You should now get the following 


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_43/bin/java

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



Simply select the version that you want to use as the default version.
Select 2 to use the new 1.6 version.
You can switch between versions this way and change back to the old version if you need to.

No comments: