How to set the default Java version
Solution 1
As per this answer: How to set default Java version?
Try providing the explicit path along with update-alternatives --install
first, and then run update-alternatives
to make your selection:
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/java-7-oracle/jre/bin/java" 1
sudo update-alternatives --config java
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/java-7-oracle/bin/javac" 1
sudo update-alternatives --config javac
Solution 2
You need to set javac
too.
sudo update-alternatives --config javac
Solution 3
I had the same problem. I had sun jdk6 installed. After
sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo update-alternatives --config javaws
a restart was necessary for me. Than it worked.
Edit: I realized it was not enough to do the steps above.
I also had to edit the environment variable:
sudo nano /etc/environment
And add (a different java version will require a different string) :
JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
Related videos on Youtube
user1461005
Updated on September 18, 2022Comments
-
user1461005 almost 2 years
I have been using Java 6 on Ubuntu 11.10, but now I want to update to version 7. I've installed version 7 via PPA as described here. If I run
sudo update-alternatives --config java
I get the following output:
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 64 auto mode 1 /usr/lib/jvm/java-6-sun/jre/bin/java 63 manual mode * 2 /usr/lib/jvm/java-7-oracle/jre/bin/java 64 manual mode
Similarly, if I run:
sudo update-alternatives --config javac
I get the output:
Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-7-oracle/bin/javac 64 auto mode 1 /usr/lib/jvm/java-6-sun/bin/javac 63 manual mode * 2 /usr/lib/jvm/java-7-oracle/bin/javac 64 manual mode
So it looks like version 7 is already the default. But if I run either
java -version
or
javac -version
The output indicates that version 6 is still the default. How can I set the default to version 7?
-
Mitch about 11 yearsHave a look at Java
-
user1461005 about 11 years@Mitch thanks, but it just says to use
update-alternatives
, which I've already tried -
Eliran Malka about 11 yearsdid you
sudo apt-get install oracle-java7-set-default
and reboot? -
Thomas Ward about 11 yearsFYI, 11.10 is End of Life.
-
-
user1461005 about 11 yearsI want version 7, not 6. The output of
update-alternatives
indicating that I'm already using version 7, butjava -version
shows that I'm still using version 6.