0

This question already has an answer here:

I have both java-6-openjdk and java-7-openjdk installed on my machine. When I check the version, I get java version "1.6.0_27". I want to run java 7 but don't really know what all I have to change to accomplish the change.

Is it as simple as changing the link from /etc/alternatives/java -> /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java /etc/alternatives/java -> /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java?

marked as duplicate by karel, Zanna, Eric Carvalho, Fabby, Charles Green Dec 7 '18 at 16:16

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

You can use sudo update-alternatives --config java to change the version of Java that is used. Don't manually change the linking of anything in /etc/alternatives/java. This is described well in Changing JVM in Java.

Alternatively, if you don't plan on using Java 6 in the future, you can remove Java 6 in its entirety. Running sudo apt-get purge openjdk-6-jre openjdk-6-jre-headless should work. If you also installed the JDK, the package name of that is openjdk-6-jdk.

1

@saiarcot895's answer works, but to automate the process (avoiding the prompting) I used:

update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/java-1.7.0-openjdk-i386/jre/bin/java" 1
udpate-alternatives --set java /usr/lib/jvm/java-1.7.0-openjdk-i386/jre/bin/java

Just remember to adjust the paths and vendors according to your case.

And make sure to check out the manual: man update-alternatives

Not the answer you're looking for? Browse other questions tagged or ask your own question.