I'm having trouble to configure oracle JDK 11 to the system. I have extracted the JDK and ran the following in the terminal

~$ export JAVA_HOME=/opt/jdk-11.0.2
~$ export PATH=$PATH:$JAVA_HOME/bin

I also did execute the command

~$ sudo update-alternatives --install "/usr/bin/java" "java" "/opt/jdk-11.0.2/bin/java" 1

and I removed the IceTea Browser plug-in (recommend by1) When I run the java -version command I get the following

openjdk version "10.0.2" 2018-07-17
OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4)
OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4, mixed mode)

while I run the javac -version I get the following result javac 11.0.2

[Note]: I performed the java configuration related actions via referring to multiple sources (YouTube videos, Linux Mint forum & other random places)

  • Well, I guess you (still) have OpenJDK version 10.0.2 installed, right?  If you’re willing to uninstall that, that would be a good step. Otherwise, try PATH=$JAVA_HOME/bin:$PATH so it finds the new version. – G-Man Mar 21 at 21:49
  • @G-Man So it is ok to uninstall the OpenJDK version? Got some feedback in the forum it's better not to uninstall it. – K.K Mar 21 at 21:51
  • @G-Man I did execute the path command provided from your side and it worked. But when I reboot my system it again point to the OpenJDK, so any suggestion in there how to configure it just once – K.K Mar 21 at 21:58
  • 1
    PATH defines where the shell looks for programs (like cat, ls, java and javac). It is searched from left to right. If you say PATH=$JAVA_HOME/bin:$PATH, you put $JAVA_HOME/bin (/opt/jdk-11.0.2/bin) at the beginning of PATH, so it looks there first. If you say PATH=$PATH:$JAVA_HOME/bin, you put $JAVA_HOME/bin at the end of PATH — and the directory of OpenJDK version 10.0.2 is in the current PATH value somewhere, so it will be found rather than 11.0.2. – G-Man Mar 22 at 2:07
  • 1
    @G-Man Thanks for the explanation and It really helped. Appreciate the effort. In early stages of using Linux, feel relieved when getting answers from the community – K.K Mar 25 at 11:31

Following https://unix.stackexchange.com/users/80216/g-man I was able to solve this scenario in the following way and also looking to the video https://www.youtube.com/watch?v=jWJPVcaubyM

  • Downloaded and extracted the Oracle JDK to the specific directory [in my case it was: usr/lib/jvm]
  • Set the global environment variable for Java by following steps:
    1. Go to prodile.d folder via Terminal [cd /etc/profile.d/]
    2. Open text editor (xed)
    3. export JAVA_HOME=/opt/jdk-11
      export PATH=$JAVA_HOME/bin:$PATH
  • Save the file as java.sh
  • The export PATH=$JAVA_HOME/bin:$PATH helps to detect the desired JDK while the Open JDK is still installed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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