Previously I had Java 1.8.0_131, then I installed JDK 1.8.0_102. Then changed the version in environment variables also, but while checking the Java version in cmd it's still showing Java 1.8.0_131. Any solution to this?
- 17,062
- 18
- 82
- 145
-
Have you tried turning it off and on again? Environment variables that you change in the system settings will not affect processes that are already running. Restart wherever you want to use the new version of Java, including your git bash, cmd.exe, or PowerShell. – Christian Hujer Jun 01 '22 at 16:19
-
1java -version in the command shell will show the version of Java that's installed, without referring to your environment variables. Why are you reverting to an older version of a JDK that is already past its support life end date? You should be using JDK 17 or, at worst, 11. – duffymo Jun 01 '22 at 16:22
-
It will refer to an environment variable: the `PATH`. – Mark Rotteveel Jun 01 '22 at 16:43
-
Please take a look on [What is the reason for "X is not recognized as an internal or external command, operable program or batch file"?](https://stackoverflow.com/a/41461002/3074564) The answer explains in full details how the environment variable `PATH` is managed used by Windows Command Processor `cmd` (and lots of other executables) to find an executable or script file which is referenced just with its file name without full path and without file extension. `cmd.exe` searches for a file with name `java` in current directory and in folder path list of `PATH` and runs whatever is found first. – Mofi Jun 01 '22 at 17:34
3 Answers
I guess you have already tried the obvious ways with paths etc, so maybe you broke the symbolic links.
So, try to write the following commands in the terminal with elevated rights:
mklink java.exe "C:\Program Files\Java\jdk1.8.0_131\bin\java.exe"
mklink javaw.exe "C:\Program Files\Java\jdk1.8.0_131\bin\javaw.exe"
mklink javaws.exe "C:\Program Files\Java\jdk1.8.0_131\bin\javaws.exe"
(Adjust the path according to the paths of your computer)
- 33
- 3
Please follow instructions in first part of this tutorial How to Change Java Versions in Windows for setting your default Java version.
Then use Windows batch files such as these for switching between Java versions:
ActivateJava_8.bat:
@echo off
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_31
setx JAVA_HOME "%JAVA_HOME%"
set Path=%JAVA_HOME%\bin;%Path%
echo Java 8 activated as user default.
ActivateJava_11.bat
@echo off
set JAVA_HOME=C:\Program Files\Java\jdk-11.0.12
setx JAVA_HOME "%JAVA_HOME%"
set Path=%JAVA_HOME%\bin;%Path%
echo Java 11 activated as user default.
Change JAVA_HOME based on your installed version and directory.
To check that Environment variables are changed as expected, run following commands on command line:
echo %JAVA_HOME%
echo %path%
- 875
- 8
-
I tried this,its working but just after a reboot its same like before – Debjit Dutta Jun 01 '22 at 18:21
-
Added link to guide for setting Java version permanently to the start of answer, you can check correctness of settings using echo commands that I have mentioned at the end of answer. – Eskandar Abedini Jun 03 '22 at 06:08
Make sure that you have installed only 1 version of java 1.8 and uninstall the others in the control panel like this:
- 1,284
- 6
- 17
- 26
- 1
- 1