BobbKitty729
BobbKitty729

Reputation: 367

javac version and java version show different on command line

Before, I had java 8. I recently installed java 11. I moved my path Java\jdk-11.0.7\bin to the top of my environment variables. When I do javac -version it gives me version 11. But when I do java -version, it gives me version 8. How do I correct this? Specifically, I want to run a jar file that was compiled using java 11.

Upvotes: 2

Views: 4351

Answers (3)

ALAN_CF
ALAN_CF

Reputation: 1

I had installed JDK16 first, then install JDK1.8. After installing JDK1.8, I automatically updated it once from 1.8.2 to 1.8.3 and then turned off the update function.

First, go to the system environment variable Move %JAVA_HOME%\bin in PATH to the forefront

Then find two values in PATH:

  • C: \ Program Files (x86) \ Common Files \ Oracle \ Java \ JavaPath
  • C: \ Program Files \ Common Files \ Oracle \ Java \ JavaPath

One of the directory is also called java.exe file deletion or moves to elsewhere Then java -version and javac -version will show version 16.0.2.

If we restore the java.exe under "C: \ Program Files (x86) \ Common Files \ Oracle \ Java \ JavaPath Then there will be a case where the version number is inconsistent

Upvotes: 0

Arvind Kumar Avinash
Arvind Kumar Avinash

Reputation: 78945

Whenever you install JDK, it asks for the path of JRE as well. There is a possibility that you mentioned a different path for JRE than the JAVA_HOME or opted out the installation. If that happened, you should uninstall both, Java 8 and Java 11 and then install Java 11 again. However, before you do this, you can try/ensure the following things:

  1. If you have put the PATH as %JAVA_HOME%\bin, it won't work if the installation path (i.e. the path of JAVA_HOME) has space. In such a case, you need to put the absolute path instead of %JAVA_HOME%\bin in the PATH environment variable.
  2. Try the commands in a new cmd window.
  3. Restart the system.
  4. Move the path of JDK bin to the top in both, User variables as well as System variables.

Upvotes: 1

Nini
Nini

Reputation: 56

In linux distors you can configure java and javac with

update-alternatives --config java
update-alternatives --config javac

Upvotes: 2

Related Questions