4

I tried to Upgrade Java on my laptop (running Windows 10) from Java 10 to Java 11. I downloaded and installed the Java 11 SDK from the Oracle website and then I added the address of the bin folder into the Path System Variable and changed JAVA_Home to point to the new jdk file.

Path System Variable looks like this:

....;C:\Program Files\Java\jdk-11.0.1\bin

And JAVA_HOME:

C:\Program Files\Java\jdk-11.0.1

Still, when I open CMD and run: java --version I get Java 10 although with javac --version I get Java 11.

enter image description here

I followed the steps described here: How to install OpenJDK 11 on Windows?

Nena
  • 376
  • 1
  • 6
  • 15
  • 8
    Java 10 JRE is presumably still in your path, and it's there before Java 11. – Michael Nov 06 '18 at 14:57
  • In command prompt run this command: `set` It will show you all environment variables you have. Or run `echo %Path%` to see only the PATH variable –  Nov 06 '18 at 15:00
  • 3
    That’s an artifact of the older JREs, which installed a `java.exe` in one of the system directories. Run `where java.exe` to find out, which executables are in the search path and delete the obsolete ones. When you are at it, do the same for `javaw.exe`. Then, all commands should be resolved correctly. The alternative is to uninstall the old Java version cleanly using its uninstaller. – Holger Nov 06 '18 at 16:37
  • Update your post to show the complete content of the **PATH** variable. – skomisa Nov 07 '18 at 00:41
  • 1
    Possible duplicate of https://stackoverflow.com/questions/53128835/switching-to-java-11-from-java-8 – Naman Nov 07 '18 at 08:28
  • OK, so I looked at the question pointed by @nullpointer and this reply [link](https://stackoverflow.com/a/53129184/4141871) as well as yours, helped me understand the problem. The `C:\ProgramData\Oracle\Java\javapath` appeared before the Java 11 path, so I moved it to the bottom and now both `java` and `javac` point to Java 11. Should I just delete the Oracle path from the Path environmental variable? – Nena Nov 08 '18 at 11:46
  • Re _Should I just delete the Oracle path from the Path environmental variable?_, first **update your post to show the content of the PATH variable** so you can get informed responses. – skomisa Nov 08 '18 at 19:47
  • I did update the question with the requested screenshot and the way I fixed my problem. – Nena Nov 09 '18 at 14:07
  • 2
    I think it'd be best if you could find a way to update the javapath link (other software could hypothetically disregard the path and directly use what's behind the javapath link); you could try the accepted answer of [this question](https://stackoverflow.com/questions/31512402/change-java-symlink), then you'd be able to remove the reference to the specific JDK11 from your PATH, leaving the javapath to link it – Aaron Nov 09 '18 at 14:21
  • 1
    @Nena It's good that you fixed your problem, but it would be better to have posted that as an answer rather than an update to the question. As things stand your question will seem unresolved because you have provided your solution within your question. – skomisa Nov 09 '18 at 19:45
  • @skomisa ok I did post it as an answer instead and made it an accepted answer so that the question will be resolved. Thank you for the answers! :) – Nena Nov 12 '18 at 12:33

2 Answers2

9

With the comment's help and looking at this question I found out that the problem was that the C:\ProgramData\Oracle\Java\javapath appeared before the Java 11 path, so I moved it to the bottom and now both java and javac point correctly to Java 11.

Here's the requested screenshot of the Path variable after I made the change in order: enter image description here

Nena
  • 376
  • 1
  • 6
  • 15
2

I upgraded to JDK 11 from JDK 8. After adding Java 11 to the path and JAVA_HOME successfully,

java -version was still pointing to the previous java version (java 8 in my case.)

Then, I ran a command "setx -m JAVA_HOME "C:\Program Files\Java\jdk-11.0.7"

Now java -version shows java 11. I hope it helps you too.

Badri Paudel
  • 1,365
  • 18
  • 19
  • If you are getting error like " access to registry path is denied " make sure to open CMD in administrative mode. That would work for sure. – Badri Paudel May 11 '20 at 14:15