Java -version shows java 8 while java 11 is installed

Viewed 34338

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

8 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!

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

In system environment variables, append PATH to point to new JDK's bin folder, and remove the old entry

%JAVA_HOME%\bin

I solved this by updating the path in user variables instead of updating in system variables.

Currently I have:

JAVA_HOME = C:\Program Files\Java\jdk-11.0.6

and

path containing %JAVA_HOME%\bin

(in User variable)

I happened to encounter the same issue and this is how I had resolved it.

In cmd/terminal - type where java, this will return all installed versions of java in the system.

enter image description here

In my case, I had installed java 11 somehow some time ago (which I don't remember when). I then deleted the 2 directories of java 11 and Oracle java in the above list carefully. Then Added the JAVA_HOME

enter image description here

and PATH - %JAVA_HOME%\bin accordingly, then it worked.

enter image description here

1: Click on Start (Windows) button.
2: Write Environmental variables.
3: Select the item.
4: Go to Advanced tab.
5: Click Environmental Variables.
6: Look for the one called "path".
7: Check for the java 7 instalation and change it to the path of your Java 11 instalation (C:\Program Files\Java\jdk-11.0.3).

Just make sure that you have added the following path in both user variables and system variable . C:\Program Files\Java\jdk-11.0.3

it will definitely work , if not try placing them at the top.

On Windows 10

Download JDK 11, run the .exe .

Follow the steps and the problem will be solved!

  1. Copied the link where the jdk is stored.
    e.g. :C:\Program Files (x86)\Java\jdk-11.0.12\ bin

  2. System Properties -> Environment Variables -> (in System variables section) -> click the Path -> Edit -> in the path list (C:\Program Files (x86)\Common Files\Oracle\Java\javapath), click next to it, the Edit text(click ok), now copy the path where the jdk is stored at the end of the path list .

  3. On the same section(in System variables section) -> click New -> variable name : JAVA_HOME and Variable Value : C:\Program Files (x86)\Java\ jdk-11.0.12 (without file bin!!) -> click ok and close the windows.

  4. Open CMD and run -> java - version and next javac -version.

I hope you found it useful.

Related