Home › Java

'java' is not recognized as an internal or external command, operable program or batch file. — how to fix

'java' is not recognized as an internal or external command,
operable program or batch file.

Quick fix: Install a JDK, then add %JAVA_HOME%\bin (e.g. C:\Program Files\Java\jdk-21\bin) to Path via System Properties → Environment Variables, and open a NEW terminal. Check with where java and java -version.

What it means

When you type java, cmd.exe (or PowerShell, which says "The term 'java' is not recognized as the name of a cmdlet...") searches each folder in the Path environment variable for java.exe. None of them contains it.

The same applies to javac, jar and keytool: they live in the JDK's bin folder.

Check what Windows sees:

where java
echo %JAVA_HOME%
echo %PATH%

Cause 1: Java isn't installed

Install a JDK (it includes the runtime). Any OpenJDK build works, for example Eclipse Temurin or Microsoft Build of OpenJDK. With winget:

winget search temurin
winget install EclipseAdoptium.Temurin.21.JDK

Many installers have an option to set Path and JAVA_HOME for you — enable it.

Cause 2: Java is installed but not on Path

Find the install folder, usually under C:\Program Files\Java\, C:\Program Files\Eclipse Adoptium\ or C:\Program Files\Microsoft\. You need the folder that contains bin\java.exe.

Set it up:

  1. Press Win, type environment variables, open Edit the system environment variables → Environment Variables...
  2. Under System variables click New: name JAVA_HOME, value e.g. C:\Program Files\Java\jdk-21 (the folder above bin).
  3. Select Path → Edit → New → %JAVA_HOME%\bin → move it up if another Java entry is listed first.
  4. OK out of all dialogs.

Avoid setx PATH "%PATH%;..." for this: setx truncates values longer than 1024 characters and merges the user and system Path into one, which can damage your Path.

Cause 3: the terminal is older than the change

Environment variables are read when a program starts. Close all cmd/PowerShell windows (and VS Code, IntelliJ, etc., which pass their environment to built-in terminals) and open a new one:

java -version
javac -version

Cause 4: 'javac' not recognized but 'java' works

You have a runtime only (JRE), or Path points at a JRE, or at C:\Program Files\Common Files\Oracle\Java\javapath, which contains only java.exe, javaw.exe and javaws.exe shortcuts. Install a JDK and put its bin first in Path.

Cause 5: typo in the Path entry

Typical mistakes:

In a script or build tool

Gradle and Maven wrappers use JAVA_HOME first. If java works but the build says JAVA_HOME is invalid, see JAVA_HOME is not set.

For a one-off session without changing settings:

set "JAVA_HOME=C:\Program Files\Java\jdk-21"
set "PATH=%JAVA_HOME%\bin;%PATH%"
java -version

In PowerShell:

$env:JAVA_HOME = "C:\Program Files\Java\jdk-21"
$env:Path = "$env:JAVA_HOME\bin;$env:Path"

Last updated 2026-12-05.