Pages

Thursday, September 18, 2014

Set Java alternatives in Linux

There are several version of java which are in use. We can have different application written in different versions of java. So to use a particular version we have to set a preferable version of java which will be used by our system. We can set java alternatives using these two methods which i prefer:

1. Scan for alternatives and choose from them
2. Manually assign alternative

1. Scan for alternatives and choose from them


If you have installed two versions of java line Java 6 and Java 7. You must be having directories for these versions in your /usr/lib/jvm directory. Now to choose from alternative use following command:


#update-alternatives --config java

This will scan for available versions of java in your system and give option two choose from them:

There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status 
———————————————————— 
* 0 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 auto mode 
1 /usr/lib/jvm/jre1.7.0/jre/bin/java 3 manual mode  
Press enter to keep the current choice[*], or type selection number: 1

Now Java 7 will be set as preferable java version.
If you are using development environment, then you have to do same thing for javac:

#update-alternatives --config javac

2. Manually assign alternative

Now, if you want to use some java version which is not installed and you have downloaded its BIN version, in that case you can manually assign java version using following cammand:

#update-alternatives --install "/usr/bin/java" "java" "/home/user/jdk1.6_37/jre/bin/java" 1
#update-alternatives --set java /home/user/jdk1.6_37/jre/bin/java

and for javac,

#update-alternatives --install "/usr/bin/java" "java" "/home/user/jdk1.6_37/bin/javac" 1
#update-alternatives --set java /home/user/jdk1.6_37/bin/javac

No comments :

Post a Comment