javac: command not found
javac: command not found
DodaTech
2 min read
javac: command not found means the Java compiler is not installed or not on PATH. You need a JDK (not just a JRE) to compile .java files into bytecode.
What It Means
The shell searched every directory in your $PATH environment variable and couldn’t find an executable named javac. Unlike java (the runtime), javac only ships with the JDK (Java Development Kit), not the JRE.
Why It Happens
- You only installed the JRE, not the JDK.
- The JDK is installed but its
bin/directory isn’t in your PATH. JAVA_HOMEis not set or points to the wrong location.- You’re on a minimal Docker image or headless server with no JDK.
How to Fix It
1. Check if a JDK is already installed
# Look for javac anywhere on the system
which javac
find / -name javac -type f 2>/dev/null
# On macOS with Homebrew
brew list | grep jdk2. Install a JDK
Ubuntu / Debian:
sudo apt update
sudo apt install default-jdkFedora / RHEL:
sudo dnf install java-latest-openjdk-develmacOS (Homebrew):
brew install openjdkWindows: Download the JDK installer from oracle.com and run it. Check “Add to PATH” during setup.
3. Locate the JDK installation
After installing, find where javac lives:
# Common locations
/usr/bin/javac
/usr/lib/jvm/java-17-openjdk-amd64/bin/javac
/Library/Java/JavaVirtualMachines/openjdk.jdk/Contents/Home/bin/javac4. Add JDK to PATH
Add this to your ~/.bashrc or ~/.zshrc:
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATHReplace the path with your actual JDK location. Then reload:
source ~/.bashrc5. Verify the fix
javac -version
# Output: javac 17.0.9Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro