On This Page
What Windows prints, word for word
You've installed the JDK. You probably also set JAVA_HOME, because every tutorial says to. Then you typed java -version into the Command Prompt that was already open, and Windows answered with this:
C:\Users\gopi>java -version
'java' is not recognized as an internal or external command,
operable program or batch file.
That's cmd.exe. The message comes from the shell, not from Java. Java never ran. PowerShell says the same thing in more words, and the wording depends on which PowerShell you have. Windows PowerShell 5.1, the one built into Windows 10 and 11:
PS C:\Users\gopi> java -version
java : The term 'java' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ java -version
+ ~~~~
+ CategoryInfo : ObjectNotFound: (java:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
And PowerShell 7, which I ran for this post (7.4.6), drops the At line block and changes "the name" to "a name":
java: The term 'java' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
If you're in Git Bash on Windows you'll see bash: java: command not found instead. Same problem, different shell, and I covered that one in java: command not found after installing the JDK.
All three mean one thing. The shell walked every folder in the PATH of this window and none of them had a java.exe in it.
Is the JDK missing, or invisible to this window?
My first instinct with this error is always that the installer failed. It usually didn't. The JDK is sitting in C:\Program Files\Eclipse Adoptium\ or wherever, PATH was updated correctly, and the window you're typing in is older than the install.
So open a new Command Prompt from the Start menu (not a new tab in an IDE) and run:
where java
where /r "C:\Program Files" java.exe
echo %PATH%
In PowerShell, use where.exe java or Get-Command java -All. Plain where in PowerShell is an alias for Where-Object and will print nothing useful.
Three outcomes. If where java now prints a path, you're done, and the old window or your IDE needs a restart. If where /r finds no java.exe on the disk, the JDK isn't installed where you think (a ZIP extracted to Downloads counts as "not installed" as far as PATH is concerned). If java.exe exists but where java still finds nothing, the PATH entry is missing or broken, and the rest of this post is about you.
Make PowerShell say it on purpose
I don't have a Windows box in the lab I used for this, so I'll be straight about what I ran. PowerShell 7.4.6 runs on Linux and uses the same command-lookup rules, which makes it a decent stand-in for the "not on PATH" half of the problem. The registry half (where Windows stores PATH) can't be reproduced off Windows, and I describe it below without fake output.
Set up an empty folder to act as a PATH with nothing useful on it:
mkdir -p lab/emptybin
JDK=/usr/lib/jvm/java-21-openjdk-amd64 # OpenJDK 21.0.13.1 on Ubuntu 24.04
E="env -i HOME=$HOME TERM=dumb PATH=$PWD/lab/emptybin"
Step 1, the error from section 1:
$ $E pwsh -NoProfile -Command 'java -version'
java: The term 'java' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
$ echo $?
1
Step 2, set JAVA_HOME and try again. This is the one everybody tries first:
$ $E pwsh -NoProfile -Command "\$env:JAVA_HOME='$JDK'; java -version"
java: The term 'java' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Step 3, put the JDK root on PATH instead of its bin folder. Still nothing:
$ $E pwsh -NoProfile -Command "\$env:PATH = '$JDK' + [IO.Path]::PathSeparator + \$env:PATH; java -version"
java: The term 'java' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Step 4, put bin on PATH:
$ $E pwsh -NoProfile -Command "\$env:PATH = '$JDK/bin' + [IO.Path]::PathSeparator + \$env:PATH; (Get-Command java).Source; java -version 2>&1 | Select-Object -Last 1"
/usr/lib/jvm/java-21-openjdk-amd64/bin/java
OpenJDK 64-Bit Server VM (build 21.0.13.1+2-1-24.04.1-Ubuntu, mixed mode, sharing)
Step 5 is the one that explains most Windows reports. Change PATH in a parent, then start a child shell from it. The child gets the new value, because a process copies its environment from whoever started it:
$ $E pwsh -NoProfile -Command "\$env:PATH = '$JDK/bin' + [IO.Path]::PathSeparator + \$env:PATH; pwsh -NoProfile -Command 'java -version 2>&1 | Select -Last 1'"
OpenJDK 64-Bit Server VM (build 21.0.13.1+2-1-24.04.1-Ubuntu, mixed mode, sharing)
The reverse never happens. A shell that's already running doesn't get updates from anyone. Teardown is rm -rf lab; nothing else was changed.
What's going on, roughly
cmd.exe and PowerShell find java by searching the folders listed in PATH, in order, for java.exe (cmd tries each extension in PATHEXT). JAVA_HOME isn't part of that search at all. Build tools like Maven and Gradle read it; your shell ignores it. So you need an entry that ends in the JDK's \bin folder, and a window that was opened after that entry existed.
Where a Windows window gets its PATH from
Windows keeps two PATH values in the registry. The system one lives under HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment and needs admin rights to change. The user one lives under HKCU\Environment and doesn't. When a process is built from those, the user Path is appended after the system Path.
Here's the part that cost me time. Nothing re-reads the registry on your behalf. Explorer gets told about changes when you save in the Environment Variables dialog, so a Command Prompt you start from the Start menu afterwards sees the new PATH. But a cmd window that was already open keeps the copy it got at launch. So does a terminal inside VS Code or IntelliJ, because those inherit from the IDE process, which inherited from Explorer back when you opened the IDE this morning. Restarting the terminal tab isn't enough. Restart the app that owns it.
A few more ways a "correct" entry still fails:
%JAVA_HOME%\binonly expands when thePathvalue is stored asREG_EXPAND_SZ. The Environment Variables dialog does that for you. Some scripts and tools write it as a plain string, and thenecho %PATH%shows a literal%JAVA_HOME%\binin the middle, which isn't a folder.- A system
Pathentry that references a variable you only defined at user level won't expand. KeepJAVA_HOMEand thePathentry that uses it at the same level. - The entry points at
C:\Program Files\Java\jdk-21instead ofC:\Program Files\Java\jdk-21\bin. Step 3 of the lab shows how that ends. - You upgraded from
jdk-21.0.4tojdk-21.0.5, the old folder got removed, andPATHstill names the old one.
The installers behave differently too, which is why "I installed Java" means different things on different machines. Adoptium's Temurin MSI has "Add to PATH" switched on by default and "Set JAVA_HOME" switched off. Microsoft's Build of OpenJDK installer also puts the JDK on PATH. Oracle's installer for JDK 25 copies java.exe, javaw.exe, javac.exe and jshell.exe into C:\Program Files\Common Files\Oracle\Java\javapath and puts that folder on PATH. A ZIP download does none of this. Nobody runs anything when you unzip a folder.
The fix for 'java' is not recognized, step by step
Before you change anything, close every terminal, open a new Command Prompt from the Start menu, and run where java again. That alone fixes it more often than you'd think.
If it's still missing, add the entry at user level, which doesn't need admin:
- Press the Windows key, type environment, and pick Edit environment variables for your account.
- Under User variables, add
JAVA_HOME=C:\Program Files\Eclipse Adoptium\jdk-21.0.5.11-hotspot(your real folder, without\bin, without quotes). - Select Path, click Edit, New, and add
%JAVA_HOME%\bin. Move it up if another Java is listed earlier. - Click OK on both dialogs, then open a new terminal and check:
where java
java -version
From PowerShell, the same change without the GUI:
$jdk = 'C:\Program Files\Eclipse Adoptium\jdk-21.0.5.11-hotspot'
[Environment]::SetEnvironmentVariable('JAVA_HOME', $jdk, 'User')
$userPath = [Environment]::GetEnvironmentVariable('Path', 'User')
[Environment]::SetEnvironmentVariable('Path', "$jdk\bin;$userPath", 'User')
This writes the expanded folder rather than %JAVA_HOME%\bin, which dodges the expansion problem but means you edit it again on the next upgrade. Your call.
And for the window you're in right now, without reopening anything:
:: cmd, this window only
set "PATH=%JAVA_HOME%\bin;%PATH%"
# PowerShell, reload both registry values into this session
$env:Path = [Environment]::GetEnvironmentVariable('Path','Machine') + ';' + [Environment]::GetEnvironmentVariable('Path','User')
What not to do: setx PATH "%PATH%;C:\...\bin". The top answers still suggest it. Microsoft's own docs say setx crops values at 1024 characters, and %PATH% in that command is the combined system-plus-user value, so you copy the whole system path into your user path and then chop the end off it. The Microsoft Q&A thread in the sources is someone who lost a pile of user variables exactly that way. Also, setx doesn't change the window you ran it in, so the next java -version fails anyway, which makes people run it a second time.
How I'd set up a JDK on a Windows box now
Install with the MSI and let it own PATH. For Temurin, tick "Set JAVA_HOME" in the custom setup screen too, since it's off by default. If you need several JDKs side by side, put only %JAVA_HOME%\bin on the user Path, take any vendor javapath folder off it, and switch versions by changing JAVA_HOME alone. One variable to change, one place Java comes from.
On a locked-down corporate laptop where you can't run installers, extract the ZIP under your user profile (say C:\Users\gopi\tools\jdk-21) and use the user-level steps above. No admin needed.
Keeping it from coming back
The habit that would have saved me the first time: after any PATH change, prove it in a fresh window with where java, not in the one you've been using. In CI, put a step at the top of Windows jobs that fails fast instead of failing forty lines into a Maven build:
where.exe java
java -version
if ($LASTEXITCODE -ne 0) { throw "java not on PATH for this runner" }
Version-wise, this error doesn't care which JDK you have. The cmd text has been the same for decades. What changes is the PowerShell wording (5.1 vs 7.x, shown in section 1) and what each vendor's installer adds to PATH, so check that again when you switch vendors or major versions. I checked the cmd and both PowerShell variants, the Oracle JDK 25, Temurin and Microsoft installer docs, and Microsoft's setx reference; the PowerShell 7 output above is from my own run, the Windows-only steps are from those docs and were not run here.
The short list
- The shell searches
PATHforjava.exe.JAVA_HOMEisn't searched, ever. - A terminal keeps the
PATHit was born with. Restart the app, not the tab. - The entry has to end in
\bin, and%JAVA_HOME%has to actually expand.echo %PATH%tells you both. - Don't use
setx PATHto add Java. It truncates at 1024 characters.
Things people also ask
Why does java -version work in one window but not another? Each window copied PATH when it started. The one that works was opened after the change; the other wasn't. Close it, or reload PATH in place with the PowerShell one-liner above.
I set JAVA_HOME, why is java still not recognized? Because cmd and PowerShell never read JAVA_HOME. Add %JAVA_HOME%\bin to Path as well, then open a new window.
java works but javac is not recognized, what's wrong? Something on PATH provides java.exe without the rest of the JDK, often an old JRE or a vendor shim folder listed before your JDK. Run where java to see which one wins, and put your JDK's \bin ahead of it.
Do I need to restart Windows after changing PATH? No. New processes started from Explorer pick it up straight away. You only need to restart the terminals and IDEs that were already open.