If you don't have admin rights, use the below command to set environment variables for java using the command prompt

setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0"
setx PATH "%PATH%;%JAVA_HOME%\bin";

Modify the environment variable.

setx -m JAVA_HOME "C:\Program Files\Java\jdk1.8.0"
setx -m PATH "%PATH%;%JAVA_HOME%\bin";
Answer from Sathiamoorthy on Stack Overflow
🌐
XDA Developers
xda-developers.com › home › windows11 › how to set the java path in windows 11
How to set the Java path in Windows 11
November 29, 2023 - Type in JAVA_HOME in the Variable name box. For Variable value, type in the path to your JDK folder — in this example, the path is “C:\Program Files\Java\jdk-21”
🌐
Medium
azimuahamed.medium.com › java-environment-variables-setup-windows-11-58fe71e43b5e
JAVA Environment Variables Setup Windows 11 | by Azim Uddin Ahamed | Medium
August 1, 2024 - In the same “Environment Variables” window, find the “Path” variable under the “System variables” section and select it. ... Click “New” and then add the path to the bin directory inside your JDK installation directory.
Discussions

java adding to path
Adding something to the path just makes the commands in the folder available everywhere system wide. The way an OS (not limited to Windows) works is that it searches certain folders for the commands you enter in the terminal (console). If it doesn't find the command, it tells you that the command you entered is not recognized. By adding a folder to the path you tell the OS to also search that particular folder when you enter a command. For Java, you need javac and java from the console. The former compiles your source code, the latter executes it. Had you not added the folder to the path, you would always need to type C:\Program Files\Java\jdk-17\bin\javac when you want to compile a program. By adding the folder to the path javac becomes sufficient. More on reddit.com
🌐 r/javahelp
3
1
August 5, 2023
Trouble changing Java version on Windows
Is your Path variable referencing JAVA_HOME or is it pointing to the original jdk location? More on reddit.com
🌐 r/javahelp
10
1
December 13, 2023
Help making a script to switch between Java JDK Versions (changing JAVA_HOME path)
When you run java -version, the OS searches for java.exe in the list of directories listed in PATH. When you run a java application with a batch file or an exe launcher, they usually search for java.exe in JAVA_HOME. So setting JAVA_HOME does not make your OS find java.exe in it, you have to set PATH too. @echo off set JAVA_HOME=... set PATH=%JAVA_HOME%\bin;%PATH% java -version More on reddit.com
🌐 r/sysadmin
10
2
February 13, 2024
I installed the latest version of java, but when I type "java --version" on terminal it shows the old one.
The most likely reason this shows up in your terminal is because your old Java version is in the PATH environment variable. Irrespective of your OS, make sure you add the path to the new java installation to your PATH environment variable, and that this new version comes earlier in your PATH variable than the older java installation. The best practice in adding java path to the environment variable is to make a new environment variable called JAVA_HOME and then using that in the PATH environment variable or any other environment variables where you need java. More on reddit.com
🌐 r/javahelp
10
7
January 14, 2023
🌐
GeekChamp
geekchamp.com › home › how to set java path in windows 11: a step-by-step guide
How to Set Java Path in Windows 11: A Step-by-Step Guide - GeekChamp
December 28, 2025 - Use Environment Variables: In Command Prompt, you can also type echo %JAVA_HOME%. If this returns a path, it indicates the JAVA_HOME variable is set; otherwise, it may not be configured. Understanding your current Java setup helps you determine the necessary steps for setting or updating the ...
🌐
Solve Your Tech
solveyourtech.com › home › programs › how to set java path in windows 11: a step-by-step guide
How to Set Java Path in Windows 11: A Step-by-Step Guide
June 3, 2024 - You might need to adjust the ‘Path’ variable to point to the desired version’s bin directory. Download and install JDK. Open System Properties. Open Environment Variables. Create a new system variable JAVA_HOME.
🌐
Support Your Tech
supportyourtech.com › home › setting the java path on windows 11: a step-by-step guide
Setting the Java Path on Windows 11: A Step-by-Step Guide
March 19, 2024 - You can test it by opening a new command prompt and typing java -version. If it shows the version number, the path is set correctly. Check if Java is installed. Locate the Java installation directory.
🌐
TechBloat
techbloat.com › home › how to set java path in windows 11: a step-by-step guide
How to Set Java Path in Windows 11: A Step-by-Step Guide - TechBloat
May 16, 2026 - Open Command Prompt and run the following command, replacing the path with your actual JDK folder: ... This creates or updates JAVA_HOME for your user account.
🌐
GeekChamp
geekchamp.com › home › how to set java path in windows 11
How to Set Java Path in Windows 11 - GeekChamp
December 27, 2025 - The default installation directories ... the result, then select Open file location. This opens the folder containing java.exe. ... Open Command Prompt and type: where java....
Find elsewhere
🌐
Coding Lap
codinglap.com › home › how to add java to the path in windows 11
How to Add Java to the PATH in Windows 11 - Coding Lap
November 3, 2025 - Type the following command and hit Enter: java -version ... java version "25.0.1"Java(TM) SE Runtime Environment (build 25.0.1+11-LTS)Java HotSpot(TM) 64-Bit Server VM (build 25.0.1+11-LTS, mixed mode) If the version number appears, congratulations ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-set-java-path-in-windows-and-linux
How to Set Java Path in Windows and Linux? - GeeksforGeeks
July 23, 2025 - Step 2: You should see the path to your Java installation printed in the Command Prompt.
🌐
Oracle
java.com › en › download › help › path.html
How do I set or change the PATH system variable?
In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK. Reopen Command prompt window, and run your java code.
🌐
javaspring
javaspring.net › blog › set-java-path-in-windows-11
Setting Java Path in Windows 11: A Comprehensive Guide — javaspring.net
After setting the Java path, you can verify it by opening a new Command Prompt or PowerShell window and running the following commands:
🌐
MacMyths
macmyths.com › home › how to set java path in windows 11: a step-by-step guide
How to Set Java Path in Windows 11: A Step-by-Step Guide - MacMyths
March 4, 2026 - This section walks through the most common failure patterns and explains exactly what each one means in the context of Windows 11. This error means Windows cannot find the java executable through the PATH variable. Either the JDK bin directory is missing from PATH, or PATH was not saved correctly. Open Environment Variables again and confirm that PATH contains %JAVA_HOME%\bin or the full path to the JDK’s bin folder. Make sure the entry is listed as a separate line and not merged into another path value. After saving changes, close all Command Prompt and PowerShell windows and open a new one.
🌐
The Windows Club
thewindowsclub.com › the windows club › general › how to set java_home in windows 11/10
How to set JAVA_HOME in Windows 11/10
Now go back to the Environment Variable window and select Path under the System variable. Click on Edit button to open Edit environment variable window. Click on New button and type %JAVA_HOME%\bin.
Published   July 13, 2024
🌐
PCNMobile
pcnmobile.com › home › how to set java path in windows 11: a step-by-step guide
How to Set Java Path in Windows 11: A Step-by-Step Guide - PCNMobile
March 12, 2026 - This is why the same command works in some systems and fails in others. PATH is not Java-specific, but Java depends on it to work globally from any command prompt or terminal window. On Windows 11, PATH affects Command Prompt, PowerShell, Windows Terminal, and most development tools.
🌐
TunesBro
tunesbro.com › home › how to set java 11 path on windows 10
How to Set Java 11 Path on Windows 10
July 19, 2023 - 7. Type the path to the JDK 11 installation directory in the "Variable value" field. For example, if the JDK 11 is installed in the "C:\Program Files\Java\jdk-11" directory, you would enter "C:\Program Files\Java\jdk-11" as the variable value. 8. Click on the "OK" button to save the changes ...
🌐
MakeUseOf
makeuseof.com › home › windows › how to set up the java_home variable on windows 11
How to Set Up the JAVA_HOME Variable on Windows 11
September 22, 2023 - Return to the Environment Variables window, select Path in the System variables section, and click Edit. ... In the field that appears, type the following and press Enter. ... Click OK to save the changes.
🌐
TutorialsPoint
tutorialspoint.com › how-to-set-temporary-and-permanent-paths-in-java
How to set Temporary and Permanent Paths in Java?\\n
There are two ways to set the path in java, First is Temporary Path and second is Permanent Path. ... Write in the command prompt: SET PATH=C:\Program Files\Java\jdk_version\bin and hit enter command.
🌐
Support Your Tech
supportyourtech.com › home › how to set java_home in windows 11: a step-by-step guide
How to Set JAVA_HOME in Windows 11: A Step-by-Step Guide
June 6, 2024 - Setting JAVA_HOME allows your system and development tools to locate the Java installation, which is crucial for running Java applications. Open Command Prompt and type echo %JAVA_HOME%. If it returns the correct path, then JAVA_HOME is set ...
Top answer
1 of 3
15

It doesn't change value in path or java -version doesn't change in current instance of cmd

You have to restart cmd for the changes to take effect as a cmd shell inherits it environment from the parent process.


So what is the correct way to switch between Java versions from the command line?

Use a set of batch files, as follows:

Being a Java developer, I always compile and test my code on different Java versions. But switching between them is a huge problem. So finally I found an easy method to do this. You have to create following batch files and place them in directory you open your command line in or in SYSTEM PATH. You can use you favorite text editor to create these files.

jdk14.bat

@echo off
echo Setting JAVA_HOME
set JAVA_HOME=C:\j2sdk1.4.2_12
echo setting PATH
set PATH=C:\j2sdk1.4.2_12\bin;%PATH%
echo Display java version
java -version

jdk15.bat

@echo off
echo Setting JAVA_HOME
set JAVA_HOME=C:\Program Files\Java\jdk1.5.0_12
echo setting PATH
set PATH=C:\Program Files\Java\jdk1.5.0_12\bin;%PATH%
echo Display java version
java -version

jdk16.bat

@echo off
echo Setting JAVA_HOME
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_11
echo setting PATH
set PATH=C:\Program Files\Java\jdk1.6.0_11\bin;%PATH%
echo Display java version
java -version

Make sure you assign the appropriate JAVA_HOME value in batch files, according to your Java installation. Whenever you want to switch between Java versions, just run the respective batch file and you are done.

Note: JAVA_HOME and the path to java must always refer to the exact same version of the JDK. If you mix them up, unpredictable things will happen!

Source Switch between different JDK versions in Windows | Oracle Pranav's Blog

2 of 3
0

The reason for this is that the variable reference in PATH is expanded at the time of the assignment to PATH, any later changes are ignored, the reference to the original value is lost. It's like making a copy of the value of the variable, not creating a reference to the variable.

set JAVA_HOME=C:\dir1
PATH=%JAVA_HOME%
set JAVA_HOME=C:\dir2
PATH

This will output C:\dir1 (value of JAVA_HOME at the time of the assignment) and not %JAVA_HOME%.

You need a script like this to call after a change to JAVA_HOME:

PATH=%JAVA_HOME%;C:\Windows\system32;C:\Windows;...