Thursday, October 18, 2012

Change default Java version in Linux (Ubuntu)

I have decide to install jdk1.6.0_24 to my Ubuntu server 10.04 LTS and I want to make this as default java in my servere.

Note: if you laready have version you want to make default simple run the step 4 .

  1. Installed above jdk using jdk-6u24-linux-x64.bin in preferred directory
    in my case  : ‘/usr/lib/jvm’
  2. Once you installed I got following directory installed  ‘/usr/lib/jvm/jdk1.6.0_24’
  3. Now run following command :
    sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.6.0_24/jre/bin/java" 1
  4. Now time to select which java version you prefer , simple run and select the version
    sudo update-alternatives --config java
      eg :
       Selection    Path                                      Priority   Status
* 0            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/jdk1.6.0_24/jre/bin/java      1         manual mode

Press enter to keep the current choice[*], or type selection number: 2
That’s it your default java now set to target version.

  5. Same time you can change $JAVA_HOME and path variable to reflect changes . I prefer global change  
       so I edit /etc/profile and append
       export JAVA_HOME=/usr/lib/jvm/jdk1.6.0_24
       export PATH=$PATH:$JAVA_HOME/bin

That’s it your server now refer to preferred java version .

No comments:

Post a Comment