Tuesday, February 18, 2014

How to set correct JDK

How to set correct JDK when multiple versions available in Linux

Method1
Sometime setting the PATH variable like below doesn't resolve the issue in some machines.

export PATH=$PATH:$JAVA_HOME/bin

Then try append the Java path before loading the rest of the PATH variables like below. 

export PATH=$JAVA_HOME/bin:$PATH

Method2

You can choose between already available alternative java by entering the below command in ubuntu

$sudo update-alternatives --config java

You will be getting an output similar to below for a user selection.

There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                     Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-7-oracle/jre/bin/java   1         auto mode
  1            /usr/lib/jvm/java-7-oracle/jre/bin/java   1         manual mode
* 2            /usr/lib/jvm/jdk1.6.0_45/bin/java         1         manual mode

Press enter to keep the current choice[*], or type selection number:

If you want to include a particular version of JDK use below command

sudo update-alternatives --install <link> <name> <path> <priority>

e.g.
$sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.6.0_45/bin/java" 1

No comments: