Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java -version shows java 8 while java 11 is installed

After installing java 11 on my system, runtime continues to be 1.8

Versions of java installed:

  • C:\Program Files\Java\jre1.8.0_201
  • C:\Program Files\Java\jdk-11.0.3

JAVA_HOME env variable value: C:\Program Files\Java\jdk-11.0.3

From command prompt running java -version command, expecting to see java 11 info but instead I see java 8.

Changing environment variable value does not change the results, rebooting doesn't seem to be doing anything.

C:\Users\user>java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) Client VM (build 25.211-b12, mixed mode)

expected is that java 11 runtime info is displayed

like image 999
TheZerg Avatar asked Jun 06 '19 16:06

TheZerg


People also ask

Does Java 11 include Java 8?

Java 11 is the first long-term support (LTS) release after Java 8. Oracle also stopped supporting Java 8 in January 2019. As a consequence, a lot of us will upgrade to Java 11. In this tutorial, we'll take a look at our options for choosing a Java 11 JDK.

Is JDK 8 and 11 the same?

It is an open-source reference implementation of Java SE platform version 11. Java 11 was released after four years of releasing Java 8. Java 11 comes with new features to provide more functionality. Below are the features which are added in the four and a half years in between these two versions.

Is Java 11 fully backward compatible with Java 8?

Java 11 is backwards compatible with Java 8. So you can swiftly change from Java 8 to 11.


2 Answers

This just happened to me yesterday. Followed instructions to the letter, and still resulted in a different Java version (1.8.0) instead of the expected (11.0.5) for my downloaded version of JDK11. Funny enough, CMD prompt returned the correct Java version (11.0.5) for the 'javac -version' command, but not for the regular 'java -version' command. I was even told to try uninstalling the existing Java load by my IT expert, as he couldn't think of anything else to try... (I did not end up removing Java)

Turns out he did help me though, perhaps accidentally, but only realized this in hindsight. He told me to try moving the path variable

%JAVA_HOME%\bin

up to the very top of the displayed list of path variables found within the [Edit environment variable] window, for the PATH System Variable option. This did not work immediately, so we figured it had no effect. But I believe this failed because it turns out I had made an oversight when typing the variable in the first place. I had written the word "home" using small caps, instead of large caps. Once I realized my mistake and fixed it to show "HOME" in large caps, my CMD prompt returned the correct java -version of (11.0.5), which matched the javac -version command result.

Please note:
I then tried moving the %JAVA_HOME%\bin variable back to the bottom of the list, where it was originally created, and the java -version command no longer displayed v.11.0.5, but returned the original answer of v.1.8.0. So, I played around a bit and found that this variable needs to be ABOVE the following variable within the existing PATH window:

C:\Program Files (x86)\Common Files\Oracle\Java\javapath

Hope this helps others as it helped me!

like image 134
Roxtar26 Avatar answered Oct 14 '22 23:10

Roxtar26


In the Environment Variables move the JAVA_HOME above like the picture under:

enter image description here

And for Java 8 you can create JAVA8_HOME as in the picture

like image 35
Beno Arakelyan Avatar answered Oct 14 '22 22:10

Beno Arakelyan