简体   繁体   中英

What would be the reason for that the Java version is NOT updated when Javac version is successfully updated?

I installed Java version 10.0.2 a few years ago, but need to update it to 11.0.2 for a particular purpose (not the latest version 13.0.2. I need it be 11.0.2).

After downloading jdk-11.0.2, I opened the environment variable window and made a change as the followings.

New path added

编辑路径

Path updated

在此处输入图片说明

But when I checked the Java version by the command prompt, it was still 10.0.2 even though Javac version was updated to 11.0.2.

在此处输入图片说明

How is it possible that Java version is not updated when Javac version gets successfully updated? It would be understandable if Javac hadn't been updated either though...

What can be the cause, and how can I fix this?

When it's time to run a program, the program is searched independently of the surrounding other technologies. This means that your javac command might not be tightly coupled to your java command.

Check your path, which is typically controlled by your PATH environmental variable. If it is finding a newer java than a javac , odds are you have a "JRE" on the PATH (which omits the "JDK" additions of compilers and other tools) before your "JVM" additions (which contain your java commands). Even if my "stab in the dark" is 100% incorrect, your PATH environmental variable is the key to unlocking the issue.

Unlike all other user variables, the user path variable doesn't override the system path variable but gets appended to it. Consequently what is happening here is that you have a path to the Oracle java installation at the very beginning of your path variable which is overriding the path that you added to the java 11 installation. The simplest solution will be to edit your system path variable and add the java 11 path at its beginning. However, have a look here for the best practices in adding java to your path.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM