[英]java -version showing different version than in path
I have jdk12
and jdk8
on my computer installed.我的电脑上安装了
jdk12
和jdk8
。 Usually jdk12
is set in the path.通常在路径中设置
jdk12
。 To run some java programs I had set path to jdk8
.要运行一些 java 程序,我已将路径设置为
jdk8
。 Now after changing the path back to /jdk-12.0.1/bin
, running java -version on cmd still returns现在将路径改回
/jdk-12.0.1/bin
后,在 cmd 上运行 java -version 仍然返回
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.在命令行调用
java
时,操作系统只使用PATH
环境变量来查找命令。 The variable JAVA_HOME
is not used here.这里没有使用变量
JAVA_HOME
。
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.因此,您只需检查
PATH
变量:JDK 安装程序将目录C:\Program Files (x86)\Common Files\Oracle\Java\javapath
添加到PATH
中。 I would suggest to remove it, so you have better control what directories are part of the PATH
.我建议删除它,这样您就可以更好地控制哪些目录是
PATH
的一部分。
If you have multiple Java installed, create the JAVA_HOME
variable and give the JAVA path which you want to use.如果您安装了多个 Java,请创建
JAVA_HOME
变量并提供您要使用的 JAVA 路径。 Use only this JAVA_HOME
variable in the PATH
variable.仅在
PATH
变量中使用此JAVA_HOME
变量。
If you wish to change the default Java, change only the JAVA_HOME
variable pointing to the required JAVA.如果您希望更改默认 Java,只需更改指向所需 JAVA 的
JAVA_HOME
变量。
This way, only one JAVA (which is required) will be present in PATH
.这样,
PATH
中只会出现一个 JAVA (这是必需的)。 Remove all other JAVA references in the PATH
variable.删除
PATH
变量中的所有其他 JAVA 引用。
Also, whenever you change the JAVA_HOME
value, open a new terminal (command prompt) to verify this change.此外,每当您更改
JAVA_HOME
值时,请打开一个新终端(命令提示符)以验证此更改。
Note: If the path contains spaces, use the shortened path name.注意:如果路径包含空格,请使用缩短的路径名。
For example, C:\Progra~1\Java\jdk1.8.0_65
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.