Developer guide · Windows and Mac
How to change the default Java (JDK) version on Windows
By Aqib Javed · Updated Nov 2, 2026
Set JAVA_HOME to the JDK's folder, for example C:\Program Files\Java\jdk-21 (without \bin), and put %JAVA_HOME%\bin at the top of Path, both under System Properties > Environment Variables. Open a new terminal and run java -version and where java. If an older Java still answers, another entry earlier in the system Path wins, often Oracle's C:\Program Files\Common Files\Oracle\Java\javapath. On Windows, Stackyard's doctor finds a broken JAVA_HOME and dead Path entries and fixes them.
Check which Java runs now
where lists every java.exe on Path in the order Windows searches them. The first one is the Java that runs. JAVA_HOME doesn't decide this: build tools such as Gradle and Maven read JAVA_HOME, but typing java runs whatever Path finds first. That is why java -version and JAVA_HOME can disagree.
:: Command Prompt
java -version
where java
echo %JAVA_HOME%
# PowerShell (where on its own means something else there)
where.exe java
$env:JAVA_HOMEHow to set JAVA_HOME and Path on Windows 10 and 11
- Open the Start menu, search for "environment variables" and choose Edit the system environment variables, or Edit environment variables for your account if you don't have admin rights. Click Environment Variables if you land on System Properties.
- Under the variables for your account (or System variables), click New. Name it JAVA_HOME and set the value to the JDK's root folder, such as C:\Program Files\Java\jdk-21. Leave \bin off the end.
- Select Path, click Edit, then New, and type %JAVA_HOME%\bin. Click Move Up until it's at the top. Delete entries that point to JDKs you removed.
- Click OK in every window, then close and reopen your terminals and IDEs. Programs read environment variables only when they start, so no restart is needed.
Windows puts the system Path before your account's Path. If the system Path already has another Java, your own entry never gets a turn. Then add %JAVA_HOME%\bin to the system Path above it, or remove that entry, both of which need admin rights.
Why java -version still shows the old version
- Oracle's installer copies java.exe, javaw.exe and javac.exe into C:\Program Files\Common Files\Oracle\Java\javapath, and older ones used C:\ProgramData\Oracle\Java\javapath. Those copies launch the Oracle Java they came with. Move the javapath entry below %JAVA_HOME%\bin or delete it.
- Other installers add their own bin folder to Path. The Eclipse Temurin MSI does by default, and sets JAVA_HOME only if you pick that option.
- The terminal or IDE was open before the change. Open a new one; an IDE may need a full quit.
- A Path entry still names a JDK you deleted. Windows skips it, but it's clutter that hides the real order.
Setting it from PowerShell, and the setx pitfalls
Both write the setting permanently, for new terminals only. Use them for JAVA_HOME and edit Path in the dialog instead. The common setx PATH "%PATH%;..." line does damage: %PATH% in a terminal is the system and user Path joined, so it copies the system entries into your user Path, expands any %VARIABLE% into a fixed folder, and setx crops anything over 1,024 characters. Microsoft's setx documentation warns that the cropping can lose data. setx /m writes the system variable and needs an administrator terminal.
# JAVA_HOME for your account, from PowerShell
[Environment]::SetEnvironmentVariable('JAVA_HOME', 'C:\Program Files\Java\jdk-21', 'User')
# the same with setx (Command Prompt or PowerShell)
setx JAVA_HOME "C:\Program Files\Java\jdk-21"Switch Java for one terminal only
This changes only the window you type it in and needs no admin rights, which makes it the quickest way to build one old project with an older JDK. Close the window and the default is back.
Flutter picks its Java in its own order: the folder set with flutter config --jdk-dir, then Android Studio's bundled JDK, then JAVA_HOME, then java on Path. So changing JAVA_HOME may not change the Java Flutter builds with. Run flutter config --jdk-dir="C:\Program Files\Java\jdk-17" to choose it, flutter config --jdk-dir="" to go back to the default, and flutter doctor -v to see which Java binary it uses.
# PowerShell
$env:JAVA_HOME = 'C:\Program Files\Java\jdk-17'
$env:Path = "$env:JAVA_HOME\bin;$env:Path"
:: Command Prompt
set "JAVA_HOME=C:\Program Files\Java\jdk-17"
set "PATH=%JAVA_HOME%\bin;%PATH%"Doing it with Stackyard
On Windows, Stackyard's doctor reads your account's and the system's variables. A JAVA_HOME that points to a missing folder, or to one with no java.exe in it, gets a button to point it at an installed JDK or remove it. A Path with folders that no longer exist, folders listed twice, or entries the system Path already has gets a Clean up PATH button, which saves the old value to a backup file first. You see each change before it runs. On Windows and Mac it lists every JDK it finds, and when the Java Flutter builds with doesn't fit an app's Gradle, it offers Point Flutter at JDK N, which runs flutter config --jdk-dir. The JAVA_HOME and Path doctor is Windows only. It's free and open source.
Questions
How do I change the Java version from the Windows command line?
- For the current window, set JAVA_HOME and put %JAVA_HOME%\bin at the front of PATH with set (Command Prompt) or $env: (PowerShell). For a permanent JAVA_HOME, use setx JAVA_HOME with the JDK folder, and edit Path in the Environment Variables dialog.
Can I change the Java version on Windows without admin rights?
- Yes, with variables for your account or per terminal. If the system Path lists another Java first, though, only an administrator can move or remove that entry.
Should JAVA_HOME include \bin?
- No. Point JAVA_HOME at the JDK's root folder, such as C:\Program Files\Java\jdk-21. Path gets the bin folder, as %JAVA_HOME%\bin.
Why does java -version show a different version than JAVA_HOME?
- Typing java runs the first java.exe on Path, and JAVA_HOME isn't consulted. Run where java to see which folder wins, then move %JAVA_HOME%\bin above it.
Do I need to restart Windows after changing JAVA_HOME?
- No. Open a new terminal and restart your IDE. Programs that were already running keep the old value until they restart.