Putting the JDK's bin folder, not a JRE's, first on PATHOn This Page
Half a JDK on your PATH
The instinct is to blame PATH in general. It can't be PATH in general, though, because java -version answered you a second ago. Something on your PATH is a working Java. It's the wrong kind of Java.
java -version prints a version. Then Command Prompt says this:
C:\Users\gopi>javac -version
'javac' is not recognized as an internal or external command,
operable program or batch file.
PowerShell uses its usual template with javac in it ("The term 'javac' is not recognized as the name of a cmdlet..."), and on Linux or macOS it's bash: javac: command not found or zsh: command not found: javac. Same cause in every shell. The shell searched each folder on PATH, found a java executable, and found no javac anywhere.
What I actually checked for this one: every shell's version of the message, which package and which folder ships each launcher, how Oracle's Windows installer behaviour changed between the Java 8 JRE and JDK 11+, and a lab on JDK 21.0.13.1 that produces the error on demand. I don't have a Windows box in this lab, so the Windows half is commands from Oracle's docs, not output I captured.
The 'javac' is not recognized error almost always has one of three causes. You installed a JRE (a runtime without a compiler) instead of a JDK. Or you have both, and PATH lists the JRE's folder and never the JDK's bin. Or you're in a container or CI image that ships a runtime only.
Two commands that settle it
Ask Java where it lives. This works on every OS:
java -XshowSettings:properties -version 2>&1 | grep java.home # Windows cmd: ... | findstr java.home
Then ask the shell where it found java, and whether it can find javac at all:
type -a java javac # bash and zsh
where java javac # cmd.exe
where.exe java; where.exe javac # PowerShell (plain 'where' is Where-Object there)
If java.home ends in something like jre1.8.0_431, temurin-21.jre, or a folder whose bin has no javac in it, you're done diagnosing. Open that bin folder and look. A JDK's bin has javac, jar, jshell, jcmd and friends. A JRE's bin has java, keytool and not much else.
If java.home points at a real JDK and javac still isn't found, the java you're running came through a shortcut folder (Oracle's javapath, /usr/bin alternatives) that only links java. More on both below.
Build a runtime with no compiler in it
You can produce this exact error on demand with any JDK 11+, because jlink will happily build you a runtime that has java and nothing else. That's also, roughly, how slim JRE images get made.
What I used: Ubuntu 24.04, OpenJDK 21.0.13.1 from the openjdk-21-jdk-headless package. No containers needed, because the whole trick is a clean shell with a controlled PATH.
Step 1, a small program to compile. Mine counts rows in a CSV, because "compile the importer" is the moment people hit this:
import java.nio.file.*;
public class Importer {
public static void main(String[] args) throws Exception {
Path csv = Path.of(args.length > 0 ? args[0] : "rows.csv");
long rows = Files.exists(csv) ? Files.lines(csv).count() : 0;
System.out.println("imported " + rows + " rows on " + System.getProperty("java.home"));
}
}
Step 2, build a runtime with only java.base in it:
$ J=/usr/lib/jvm/java-21-openjdk-amd64
$ $J/bin/jlink --add-modules java.base --strip-debug --no-header-files --no-man-pages --output jre21
$ ls jre21/bin
java
keytool
Step 3, start a shell whose PATH has that runtime and a folder of plain tools (ls, cat), and nothing else. env -i wipes the inherited environment so your real PATH can't leak in:
$ env -i PATH="$PWD/jre21/bin:$PWD/tools" /bin/bash --norc --noprofile
$ java -version
openjdk version "21.0.13.1" 2026-11-17
OpenJDK Runtime Environment (build 21.0.13.1+2-1-24.04.1-Ubuntu)
OpenJDK 64-Bit Server VM (build 21.0.13.1+2-1-24.04.1-Ubuntu, mixed mode)
$ javac Importer.java
bash: javac: command not found
$ echo $?
127
$ type -a javac
bash: type: javac: not found
That's the reproduction. java works, javac doesn't exist, exit code 127 (the shell's "command not found"). Dash, which is /bin/sh on Debian and Ubuntu and what a lot of CI RUN lines use, words it as /bin/sh: 1: javac: not found.
Step 4, the near-miss that confused me. I tried the source-file launcher, java Importer.java, which compiles in memory and runs. On this runtime it dies:
$ java Importer.java
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.InternalError: Module jdk.compiler not in boot Layer
at java.base/sun.launcher.LauncherHelper.loadModuleMainClass(Unknown Source)
at java.base/sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
If you see that line in a container, it's the same disease: no compiler module in the image.
Step 5, the fix in miniature. Put the JDK's bin in front:
$ env -i PATH="$J/bin:$PWD/jre21/bin:$PWD/tools" /bin/bash --norc --noprofile
$ javac -version
javac 21.0.13.1
$ javac -d out Importer.java && java -cp out Importer rows.csv
imported 3 rows on /usr/lib/jvm/java-21-openjdk-amd64
Teardown is rm -rf jre21 out and closing the shell. Nothing outside the lab folder changed.
Start here if you're in a hurry
java and javac are two separate programs in two folders that may or may not be the same folder. Your shell finds each one independently. Right now it finds a java that has no javac beside it. Put the bin folder of a real JDK on PATH, before anything else that contains a java, and open a new terminal.
Why java and javac travel separately
Here's the part I didn't expect. javac isn't the compiler. It's a 14 KB launcher. On my box bin/java is 14,456 bytes and bin/javac is 14,512: same native launcher, with "start the main class in the jdk.compiler module" baked in. The compiler itself lives in the runtime's module image as jdk.compiler. So "do I have javac?" is really two questions: is the launcher file on PATH, and is the jdk.compiler module in the runtime?
Different installs answer those differently, and that's where every variant of this error comes from.
Linux packages split them on purpose
On Debian and Ubuntu, the JRE and JDK are separate packages, and I checked who owns what:
$ dpkg -S /usr/lib/jvm/java-21-openjdk-amd64/bin/javac /usr/lib/jvm/java-21-openjdk-amd64/bin/java
openjdk-21-jdk-headless:amd64: /usr/lib/jvm/java-21-openjdk-amd64/bin/javac
openjdk-21-jre-headless:amd64: /usr/lib/jvm/java-21-openjdk-amd64/bin/java
$ dpkg -S /usr/lib/jvm/java-21-openjdk-amd64/lib/modules
openjdk-21-jre-headless:amd64: /usr/lib/jvm/java-21-openjdk-amd64/lib/modules
Look at the last line. The module image, jdk.compiler included, ships in the JRE package. So on an Ubuntu machine with only openjdk-21-jre-headless, javac is missing but java Importer.java works, which is the opposite of my jlink lab. I spent a while thinking my lab was broken before I checked the package manifest. (This is Ubuntu's packaging; a jlink'd or vendor JRE image usually leaves jdk.compiler out entirely.)
Then there's the alternatives system. /usr/bin/java and /usr/bin/javac are separate links managed separately:
$ update-alternatives --display javac | head -2
javac - auto mode
link best version is /usr/lib/jvm/java-21-openjdk-amd64/bin/javac
Run update-alternatives --config java to switch to 17 and javac stays on 21, or stays missing if 17 was installed as a JRE. That's how you end up with java -version and javac -version disagreeing.
Windows: the javapath folder
Oracle's Windows installers add a shortcut folder to PATH instead of the JDK's bin. For JDK 11 and later it's C:\Program Files\Common Files\Oracle\Java\javapath, and per Oracle's JDK 22 install guide it holds java.exe, javaw.exe, javac.exe and jshell.exe.
So a current Oracle JDK does give you javac. The old advice that "javapath only has java.exe" is JRE-era: the Java 8 JRE installer from java.com puts only java.exe, javaw.exe and javaws.exe there, as JDK-8259858 spells out. That's the classic setup behind this error: an old Java 8 JRE sitting first on PATH from years ago, a new JDK installed from a ZIP or a vendor MSI that never touched PATH, and java -version happily printing 1.8.
The other Windows favourite: PATH has C:\Program Files\Java\jdk-21 without \bin on the end. Nothing in that folder is executable, so it's as if the entry weren't there.
macOS and Docker
On macOS, /usr/bin/java and /usr/bin/javac are system stubs that hand off to whatever /usr/libexec/java_home picks from /Library/Java/JavaVirtualMachines. A folder named something.jre there (Temurin ships macOS JRE packages that install that way) is a runtime only. /usr/libexec/java_home -V lists what's installed; anything ending in .jre can't compile. I didn't run this on a Mac for this post.
In Docker, the tag decides. eclipse-temurin:21-jre is a runtime image, eclipse-temurin:21-jdk has the compiler. A multi-stage build that runs javac (or Maven, or Gradle) in the -jre stage fails with the /bin/sh message from the lab. I couldn't pull images from this sandbox, so that's from the image naming, not a captured run.
Fixing 'javac is not recognized' for real
Check first, then change one thing. Before touching anything, confirm a JDK exists on disk at all, because if it doesn't, no PATH edit will save you.
Windows
- Find a JDK:
dir "C:\Program Files\Java" "C:\Program Files\Eclipse Adoptium" "C:\Program Files\Microsoft"and look for a folder withbin\javac.exeinside. No JDK? Install one (Temurin, Oracle, Microsoft Build of OpenJDK, any of them). - Open System Properties → Environment Variables. Set
JAVA_HOMEto the JDK folder (notbin). - Edit
Pathand add%JAVA_HOME%\bin. Move it above any...\Oracle\Java\javapathentry and any oldjre1.8.0_*\binentry. Order matters: the first folder with ajava.exewins. - If you don't need the Java 8 JRE anymore, uninstall it from Apps. That removes its
javapathentry too. - Open a new terminal (and restart your IDE) and run
where javac. Old windows keep their oldPATH.
Linux
sudo apt install openjdk-21-jdk-headless # Debian/Ubuntu: -jdk, not -jre
sudo dnf install java-21-openjdk-devel # Fedora/RHEL: the compiler is in -devel
sudo apk add openjdk21-jdk # Alpine
sudo update-alternatives --config javac # then pick the same version as java
If you installed a tarball by hand, put export PATH="$JAVA_HOME/bin:$PATH" in the startup file your shell actually reads; the java: command not found post has the details on which file that is.
Docker and CI
Compile in a -jdk image, run in a -jre one:
FROM eclipse-temurin:21-jdk AS build
WORKDIR /src
COPY Importer.java .
RUN javac -d /out Importer.java
FROM eclipse-temurin:21-jre
COPY --from=build /out /app
ENTRYPOINT ["java", "-cp", "/app", "Importer"]
On GitHub Actions, actions/setup-java installs a JDK by default; the problem there is usually a later step or a container job image overriding it.
Things that aren't fixes
Copying javac.exe into the JRE's bin. It's a launcher, and without the jdk.compiler module in that runtime it has nothing to launch. Calling the JDK's javac by full path every time works, but your build tool won't do that, so you'll be back here in an hour.
There's one honest escape hatch on an Ubuntu box with only the JRE package, since the module is there: java -m jdk.compiler/com.sun.tools.javac.Main -version printed javac 21.0.13.1 for me. Fine in an emergency. Install the JDK package anyway.
Getting the structure right up front
One JDK per major version, installed somewhere boring, and exactly one bin on PATH that you control. On a laptop, let a version manager own it (SDKMAN on Linux and macOS, or JAVA_HOME plus %JAVA_HOME%\bin on Windows), and uninstall any JRE you don't run a specific app with. On servers and images, pick -jdk for anything that builds and -jre only for the final runtime stage.
And pin the toolchain in the build itself (Maven toolchains, Gradle's java.toolchain) so the compiler version doesn't depend on whatever a shell happens to find.
The test that would have caught this
Add a first step to any setup script or CI job that fails loudly when the two halves disagree:
java_home=$(java -XshowSettings:properties -version 2>&1 | sed -n 's/^ *java.home = //p')
[ -x "$java_home/bin/javac" ] || { echo "java on PATH is a runtime only: $java_home"; exit 1; }
[ "$(javac -version 2>&1 | cut -d' ' -f2)" = "$(java -XshowSettings:properties -version 2>&1 | sed -n 's/^ *java.version = //p')" ] || echo "warning: java and javac versions differ"
Version notes, since this changed over time: Oracle stopped shipping a separate JRE after Java 8, and from JDK 11 the Oracle installer's javapath folder includes javac.exe. Vendors such as Adoptium still publish JRE builds for current LTS versions, and Linux distros still split JRE and JDK packages, so this error is not going away. It only moved from Windows desktops into containers.
Screenshot this bit
javaworking proves nothing aboutjavac. They're found separately onPATH.- Ask
java.homewhere the running Java lives. If itsbinhas nojavac, it's a JRE. - Windows:
%JAVA_HOME%\binmust sit above anyjavapathor oldjre1.8.0entry. New window afterwards. - Linux: install the
-jdk(or-devel) package, then line upupdate-alternativesfor both. - Containers: compile in
-jdk, run in-jre.
Quick answers
Why does java work but javac doesn't?
Because they're separate executables and your shell finds each one on its own. The java it finds belongs to a JRE, or to a shortcut folder like Oracle's Java 8 javapath, and no folder on PATH contains javac. Put the JDK's bin first on PATH. The JDK vs JRE vs JVM post covers what each one includes.
How do I know if I have a JDK or a JRE installed?
Run java -XshowSettings:properties -version and read java.home, then look in that folder's bin. A JDK has javac, jar and jshell; a JRE doesn't. On macOS, /usr/libexec/java_home -V lists installs, and ones ending in .jre are runtimes only.
Which package gives me javac in Docker or CI?
Use a -jdk image tag such as eclipse-temurin:21-jdk, or install openjdk-21-jdk-headless on Debian and Ubuntu, java-21-openjdk-devel on Fedora and RHEL, openjdk21-jdk on Alpine. The -jre and -headless JRE packages run code but can't compile it.
Do I still need JAVA_HOME if javac works?
Not for javac itself; the shell only uses PATH. Maven, Gradle and most IDEs read JAVA_HOME, though, and if it points at a JRE you'll get Maven's "No compiler is provided in this environment" instead, which is the same problem one layer up.