Monday, June 23, 2014

Switch existing Java versions in Linux

Instigation:
I have installed two Java versions in my machine(6 and 7). I was using Java 6 because of a product which requires it. But later I wanted to switch from Java 6 to Java 7. 

step 1:  Check available versions.

Type following command in CLI: 
 sudo update-alternatives --config java

give the proper selection number as you want.




step 2:  Update your bashrc.

command: vim ~/.bashrc

Set(comment the current one and add new variable) or update(change existing one) the JAVA_HOME and PATH shell variables as follows:
 
export JAVA_HOME="/usr/lib/jvm/java-7-oracle"
export PATH="$PATH:$JAVA_HOME/bin"

Save and exit:
Press Esc  and then press colon(:)
Type "wq!"
Press Enter

step 3:  Verify new Java settings.

command: java -version

Sample output:

bhagya@bhagya-ThinkPad-T530:~$ java -version
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)