'How to set Default Java version on windows 10?

I had installed java v 1.8 on Windows 10 for years. JAVA_HOME and Path variables were updated. Then I installed Java 18 today. Did update JAVA_HOME and Path variables according to it.

When I execute java -version command it returns the correct version (v18).

Next, I installed java v11 and updated JAVA_HOME and Path variables for v11. but when I execute java -version it returned v18 as result.

Then I uninstalled v18 from the control panel and executed the same command. Then I returned the correct value. v11

  1. Why did java -version return latest version (v18) even I have updated JAVA_HOME and Path variables for v11 ?

  2. Where is this information saved on PC?



Solution 1:[1]

Try running

where Java

Make sure that this returns the path to your Java version you want. Should return something like:

C:\Program Files\Java\jdk-11.0.10+9\bin\java.exe

If not then the environment variables were not set correctly. Make sure that your JAVA_HOME is pointing to the instillation folder, and the path to the \bin folder.

Hope this helps!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sushi