Home > OS >  java version conflict on windows
java version conflict on windows

Time:09-15

I usually work with java 11 on my computer but then I installed java 8 to run both.

Now when I run java -version, it shows java 8. I find it odd because my environment variables point towards 11. In addition javac -version shows 11. Seems it's not clear to my system which one is the current version.

I try many solution I found here but nothing seems to work, unless I uninstall java 8.

How can I resolve this and cleanly switch between both (or many) java version on my pc ?

CodePudding user response:

The operating system on your computer uses the PATH environment variable to locate the javac executable. Hence the bin subdirectory of your JDK 11 installation appears in the value of the PATH environment variable. Note that the bin subdirectory of your JDK 8 installation may also appear in the value of PATH but since you say that javac -version shows 11, that means that if both JDK 11 bin and JDK 8 bin are on the PATH then JDK 11 appears before JDK 8. That's why, when you issue javac -version it shows 11.

Regarding the output of command java -version that depends on other details which I could not find in your question, including (but not only) which JDK 8 you installed. If it is Oracle's and if you installed JDK 8 after you installed JDK 11, that would explain why java -version shows 8.

Note that if you want to run a specific JDK, you can always enter the full path to the file java.exe when you enter the command - rather than just java.

CodePudding user response:

On windows 10, you have to change both JAVA_HOME and Path.

  1. Change JAVA_HOME to point towards your desired version.
  2. In Path make sure the desired version comes before the other one.

This works for me(i switch frequently between java 8 and 11).

  •  Tags:  
  • java
  • Related