25

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

Abra
  • 19,142
  • 7
  • 29
  • 41
TheZerg
  • 309
  • 1
  • 3
  • 9

8 Answers8

30

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!

Roxtar26
  • 301
  • 3
  • 3
  • I've been encountering this issue since I was in college, to myself, I thought nah, as long as my compiles are working, I'm fine, not until my project in a company now requires v11. And now I had to really use v11 instead of 8. Damn, I didn't know its just that location of JAVA_Home above the path, now it is indeed displaying v11 instead of 8 if I move the java home path abobe the */javapath value – iamjoshua Dec 13 '19 at 05:50
  • PS: Had to close the entire IntelliJ instance by ending the process tree and then opening InteliJ again for the environment variables being used in IntelliJ to refresh and use the recently updated system variables. So when your change is not shown in IntelliJ terminal, but shown in windows terminal, make sure to close all IntelliJs processes and open the app again for it to refresh the env. variables stored in its local storage. – iamjoshua Dec 13 '19 at 06:03
  • If moving the v11 entry up to the top of the PATH list fixes the problem, it means that there is another entry in the list that points to another version of Java. Also, remember to restart your command prompt/Shell for the changes to take effect. Some have reported that they need to do a full system restart to see the changes as well. – Aterxerxes Jan 29 '22 at 19:33
5

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

Beno
  • 945
  • 11
  • 22
2

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

%JAVA_HOME%\bin
TechFree
  • 2,600
  • 1
  • 17
  • 18
  • Doing this now throws the following message: 'java' is not recognized as an internal or external command, operable program or batch file. – TheZerg Jun 07 '19 at 14:21
2

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)

2

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

Dhamo
  • 1,171
  • 3
  • 19
  • 41
1
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).
Paco Abato
  • 3,920
  • 4
  • 31
  • 54
1

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.

mohan
  • 31
  • 3
-1

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.