I have jdk12
and jdk8
on my computer installed. Usually jdk12
is set in the path. To run some java programs I had set path to jdk8
. Now after changing the path back to /jdk-12.0.1/bin
, running java -version on cmd still returns
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)
I decided to assemble my comments to an answer:
When calling java
on the command line, the OS only uses the PATH
environment variable to look for the command. The variable JAVA_HOME
is not used here.
So you simply should examine the PATH
variable: The directory C:\Program Files (x86)\Common Files\Oracle\Java\javapath
is added to the PATH
by the JDK installer. I would suggest to remove it, so you have better control what directories are part of the PATH
.
If you have multiple Java installed, create the JAVA_HOME
variable and give the JAVA path which you want to use. Use only this JAVA_HOME
variable in the PATH
variable.
If you wish to change the default Java, change only the JAVA_HOME
variable pointing to the required JAVA.
This way, only one JAVA (which is required) will be present in PATH
. Remove all other JAVA references in the PATH
variable.
Also, whenever you change the JAVA_HOME
value, open a new terminal (command prompt) to verify this change.
Note: If the path contains spaces, use the shortened path name. For example, C:\Progra~1\Java\jdk1.8.0_65
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.