Skip to content
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_HOME is 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 jdk

2. Install a JDK

Ubuntu / Debian:

sudo apt update
sudo apt install default-jdk

Fedora / RHEL:

sudo dnf install java-latest-openjdk-devel

macOS (Homebrew):

brew install openjdk

Windows: 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/javac

4. 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:$PATH

Replace the path with your actual JDK location. Then reload:

source ~/.bashrc

5. Verify the fix

javac -version
# Output: javac 17.0.9
What's the difference between javac and java?
java runs compiled programs (it needs a JRE); javac compiles source files into bytecode (it needs a JDK). The JDK includes both. Installing only a JRE gives you java but not javac.
Do I need sudo to install the JDK?
On Linux, system-wide installs need sudo. On macOS with Homebrew, you may not need sudo. You can also use SDKMAN (sdk install java) which installs to your home directory and manages PATH automatically — no sudo required.
How do I set JAVA_HOME permanently on Windows?
Go to System Properties → Environment Variables → New. Set variable name JAVA_HOME and value to the JDK path (e.g. C:\Program Files\Java\jdk-17). Then edit Path and add %JAVA_HOME%\bin. Restart your terminal.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro