Ubuntu: change the path from OpenJDK 6 to Oracle JDK 7


https://help.ubuntu.com/community/Java

http://stackoverflow.com/questions/21115133/ubuntu-change-the-path-from-openjdk-6-to-oracle-jdk-7 


Ubuntu: change the path from OpenJDK 6 to Oracle JDK 7

i.gif?e=eyJhdiI6NDE0LCJhdCI6NCwiYnQiOjAs

up vote        10        down vote        favorite        

4

After downloading the latest .tar file I ran tar zxvf jdk-7u45-linux-x64.tar.gz to extract java files.

Set the path in .bashrc file (vi ~/.bashrc) as below;

export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_45/bin/java
export PATH=$PATH:/usr/lib/jvm/jdk1.7.0_45/bin
export JDK_HOME=/usr/lib/jvm/jdk1.7.0_45    
export JRE_HOME=/usr/lib/jvm/jre1.7.0_45

Now, running command java -version or which java, java PATH still pointing to the older java version (java version "1.6.0_27").

I know default ubuntu takes OpenJDK path. I have to change the path as latest version as my system environment variable set in .bashrc file.

Also, sudo update-alternatives --config java

Selection    Path                                      Priority   Status------------------------------------------------------------
  0            /usr/lib/jvm/java-7-oracle/jre/bin/java    1062      auto mode  1            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      manual mode  2            /usr/lib/jvm/java-7-oracle/jre/bin/java    1062      manual mode* 3            /usr/lib/jvm/jdk1.7.0_45/bin/java          1         manual modePress enter to keep the current choice[*], or type selection number: 3

   

java classpath ubuntu-10.04    

shareimprove this question

edited Jan 14 '14 at 14:34    


           

asked Jan 14 '14 at 13:47    

   

Devendra Singh
       92119    


add a comment                    

3 Answers

active        oldest        votes

   

up vote        21        down vote

Ubuntu (and Debian) have an elegant way to manage libraries like the jdk.

Using update-alternatives you can manage multiple jdk libraries on the same system, choosing which one you want to use as the main one.

First you have to install an alternative for the new installed jdk:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0_45/bin/java" 1sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0_45/bin/javac" 1

In this way you install the new jdk as an alternative to the original one. Then you can choose which one you wan to use:

sudo update-alternatives --config java
sudo update-alternatives --config javac

You will be asked to choose which jdk you want to use, on my system I have:

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

  Selection    Path                                           Priority   Status------------------------------------------------------------
  0            /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java   1061      auto mode  1            /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java   1061      manual mode* 2            /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java   1051      manual modePress enter to keep the current choice[*], or type selection number:

At any time you can see what alternatives you have for java or javac using the --list option:

sudo update-alternatives --list java
sudo update-alternatives --list javac

To see more options check the update-alternatives man page.

shareimprove this answer

edited Nov 21 '14 at 0:08    

   

sesotek
       32    

answered Jan 14 '14 at 13:50    

   

Atropo
       6,48221435    




while running sudo update-alternatives --install "/usr/bin/javac" "java" "/usr/lib/jvm/jdk1.7.0_45/bin/java" 1 update-alternatives: error: alternative link /usr/bin/javac is already managed by javac.                �C                     Devendra Singh                Jan 14 '14 at 13:57                                                                            

1                        

@DevendraSingh you have a typo: dont confuse javac with java you have "/usr/bin/javac" pointing to "/usr/lib/jvm/jdk1.7.0_45/bin/java"                �C                     Atropo                Jan 14 '14 at 13:58                                                                                                



I still unable to change the path.                �C                     Devendra Singh                Jan 14 '14 at 14:27                                                                            



Post, in your question, the output of update--alternatives --list java                �C                     Atropo                Jan 14 '14 at 14:29                                                                            

add a comment                    

i.gif?e=eyJhdiI6NDE0LCJhdCI6NCwiYnQiOjAs

up vote        4        down vote

You probably want to do

export PATH=/usr/lib/jvm/jdk1.7.0_45/bin:$PATH

OpenJDK is probably still in the path, and Linux will use the first java it finds.

If you don't need it, I would recommend uninstalling OpenJDK.

shareimprove this answer

answered Jan 14 '14 at 13:49    

   

Petter
       2,221821    


add a comment                    

           

up vote        3        down vote

Try typing the following in your terminal.

sudo update-alternatives --config java

The output will be some choices and you can select the correct one which installed to your computer.

shareimprove this answer

edited Aug 26 '14 at 4:56    


           

answered Aug 25 '14 at 14:00    

   

gihandilanka
       617    


add a comment


你可能感兴趣的:(fun)