How to set default JDK version in Ubuntu.

Today we are going to talk about how to set default JDK version when you have multiple JDK version installed in Ubuntu. Recently I ran into a problem while using Eclipse version named Neon. The error looks like below.

set default JDK version to avoid error UseStringDeduplication

The reason for this error is  I have installed Java 8 and Java 9 in my Ubuntu 16.04.  Since I installed Java 9 using apt-get it was the default JDK. But According to Eclipse Neon Documentation https://wiki.eclipse.org/Eclipse/Installation#Eclipse_4.6_.28Neon.29

Neon Only supports up to Java 8 but currently, my system JDK was Java 9. So that was the root cause of the error. So the solution would be set default JDK version into Java 8. One solution can be seems as remove Java 9, but I’m pretty sure not many would love that solution :D.  Let’s figure out how to change default JDK into Java 8 without removing Java 9.

First of all, make sure which version of JDK currently used as default. Run below command in Terminal (If you don’t how to get Terminal just press it’s Shortcut keys Ctrl + Alt + T ).

java -version

`If you want to see which are the versions of JDK installed in Ubuntu then run below command in the Terminal.

sudo update-java-alternatives --list 

Then choose which version you want to set. After that run below command. Please replace square brackets with your JDK version you want to set. In my case it was java-8-oracle.

sudo update-java-alternatives --set [JDK/JRE name e.g. java-8-oracle]

Now you have successfully set default JDK version to Java 8 (In my scenario) After that my Eclipse error solved. Because now default system JDK is changed to JDK 8. You can make sure it by running the First command I gave to you. Post created using below answer I gave in StackOverflow.

https://stackoverflow.com/questions/38574448/eclipse-error-usestringdeduplication/49495943#49495943

About Author:

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.