“javac is not recognized”, explained and fixed

Windows prints 'javac' is not recognized as an internal or external command when the terminal cannot find the Java compiler. There are only two possibilities: no JDK is installed (a JRE can run Java programs but contains no compiler), or a JDK is installed but its bin folder is not on the PATH the terminal searches. The second is far more common, especially after installing the JDK with default options and opening a terminal that was started before the install.

The fix, in order

  1. Confirm a JDK exists: look for a folder like C:\Program Files\Java\jdk-21 (or the Eclipse Temurin / Amazon Corretto equivalent). If only a jre folder or nothing exists, download and install a JDK (Temurin and Oracle JDK are the common choices); a JRE alone will never provide javac.
  2. Set JAVA_HOME: in Windows Settings, search “environment variables”, and under System variables create JAVA_HOME pointing at the JDK folder itself (for example C:\Program Files\Java\jdk-21), not at its bin subfolder.
  3. Add the compiler to PATH: edit the System Path variable and add %JAVA_HOME%\bin. Using the variable keeps future JDK upgrades to a one-place change.
  4. Open a brand-new terminal and verify with javac -version and java -version. Terminals inherit environment variables at launch; an old window will keep reporting the error even after everything is set correctly.

If it still fails after that

  1. An older Java entry earlier in PATH wins: Windows uses the first match. Old Oracle installers added entries like C:\Program Files (x86)\Common Files\Oracle\Java near the front; the version printed by java -version reveals whose binary actually ran.
  2. The versions disagree: javac reports one version and java another when two installs are mixed on PATH. Align both to the same JDK via the steps above.
  3. IDE versus terminal: an IDE uses its own configured SDK, so code compiling in the IDE proves nothing about the terminal; conversely a working terminal does not configure the IDE. Each has its own setting.

Common questions

Is javac included in the JRE? No. The JRE (and the runtime inside a JDK) runs compiled programs; the compiler lives only in the JDK. Modern Java distributions mostly ship the JDK alone, which is why installing “Java” from a vendor's JDK page solves it.

Why did it work in the IDE but not in Command Prompt? The IDE was pointed at a JDK in its own settings. The terminal relies on Windows environment variables, which the IDE does not set for it.

I set the variables and it still fails in the same window, why? Environment variables are read when a process starts. Any terminal, editor, or IDE opened before the change holds the old values; restart the terminal (and the editor, if it launches builds) to pick them up.

Related errors

'java' is not recognized · Could not find or load main class · 'pip' is not recognized