Home > Back-end >  Unbale to change JAVA HOME path
Unbale to change JAVA HOME path

Time:06-06

I want to update jdk version from jdk1.8.0_18 to jdk1.8.0_262 in windows server 2008, so i have both versions in the system and i changed JAVA HOME in environment variable and updated in PATH as well. But when i type in command prompt java -version , it return old version and not updating to newer version.

I have tried multiple options, but it is referring to older versions. I know this basic but need some help to troubleshot.

CodePudding user response:

What is the path listing for java below commands from cmd ?

echo %PATH%
SET

CodePudding user response:

Yup, we've all been there: changing the JDK making you want to change your computer in the proccess. Here's some troubleshooting tips:

  • Double check that you deleted the old path from the environmental variable. When you do the java command, windows looks for java.exe starting from the first directory in the path variable until it finds it, so if you have something like
    C:\User\...\jdk\old_jdk\bin;C:\windows\system32;C:\User\...\jdk\new_jdk\bin; it would stop searching after it finds it in the old jdk's bin folder.

  • Sometimes there may be both a path environmental variable defined for the user and for the system, if this is the case make sure the old JDK is not sneakily defined on the system path as well.

If you're really desperate (although not recommended as it will probably confuse you and others in the future), you can also rename the new JDK to the old JDK, so when windows tries to find the old JDK it would instead use the new JDK.

In the meantime if you'd need to use the new JDK, you should be able to use either %JAVA_HOME%\bin\java.exe JavaFile.java or "C:\Users\...\jdk\jdk1.8.0_262\bin\java.exe" JavaFile.java(or wherever your JDK is) instead of java JavaFile.java. Similarly javac can be used by replacing java.exe to javac.exe.

Hope this helps!

  • Related