Getting started
'javac' is not recognized: How to Fix It on Windows and Mac
Published on October 22, 20266 min read
You type javac Main.java into the terminal, and instead of a compiled file you get an error message. This happens to almost everyone setting up Java for the first time. Here you'll learn what the message means, how to find the cause in two minutes and how to fix it on Windows and macOS.
What the message means
The error looks slightly different depending on your system. In the Windows Command Prompt it says:
'javac' is not recognized as an internal or external command, operable program or batch file.
In PowerShell you're told that the term 'javac' is not recognized as the name of a cmdlet, function, script file or operable program. On a Mac you see zsh: command not found: javac or the message "Unable to locate a Java Runtime". If your system runs in another language, the wording is translated, but the meaning is the same.
It always comes down to one thing: the terminal can't find the program javac. This has nothing to do with your Java code. Your code hasn't even reached the compiler yet.
Find the cause in two minutes
Open a new terminal and enter these two commands:
java -version javac -version
Now there are three cases:
java -version | javac -version | Cause |
|---|---|---|
| Error | Error | No Java is installed, or the PATH is missing completely. |
| Shows a version | Error | You only have a runtime (JRE), not a JDK, or the PATH points to an old Java. |
| Shows a version | Shows a version | Everything is fine. The old terminal just didn't know about the new PATH yet. |
The third case is more common than you'd think. A terminal reads the PATH when it starts. If you install Java while it's open, you have to close it and open a new one. That also applies to the terminal inside your IDE.
The difference between JRE and JDK
The JRE can only run Java programs. Only the JDK contains the compiler javac. If you installed Java years ago for a game or some program from java.com, you often only have a runtime. Then java works, but javac is missing. The fix is to install a JDK, ideally a current LTS version such as JDK 25.
The fix on Windows
1. Install a JDK
Download a JDK for Windows x64, for example from Oracle or Eclipse Temurin. According to Oracle's installation guide, the Oracle installer copies java.exe and javac.exe into a javapath folder that is put on the PATH. The Temurin installer has an option to add Java to the PATH. Both installers need admin rights. If you don't have them, read Java without admin rights.
2. Check where the JDK is
The Oracle JDK usually ends up in a folder like this:
C:\Program Files\Java\jdk-25
Inside it there's a bin subfolder. That's exactly where javac.exe lives. Check in File Explorer what the folder is called on your machine.
3. Set the PATH by hand
If javac is still missing in a new terminal, add the folder yourself:
- Press the Windows key and search for "environment variables".
- Choose "Edit environment variables for your account". You don't need admin rights for this.
- Under "User variables", select the entry
Pathand click "Edit". - Click "New" and paste the
binfolder, for exampleC:\Program Files\Java\jdk-25\bin. - Confirm every window with OK.
- Close every open terminal and open a new one.
On a Windows system in another language, these labels are translated.
Three mistakes come up again and again:
- Forgetting
\bin. The PATH must point to thebinfolder, not to the JDK folder itself. - An old Java comes first.
where javaandwhere javacshow you which files Windows really finds. If an old Java 8 path sits before your JDK, move your entry up with "Move Up". JAVA_HOMEset wrong. Some tools also needJAVA_HOME. It points to the JDK folder without\bin.
The fix on macOS
On a Mac things are a little different. macOS ships small placeholders for java and javac, but no real Java. Without a JDK, they report that no Java runtime could be found.
1. Install the right JDK
First check which chip your Mac has: Apple menu, then "About This Mac". If it says a chip like "Apple M2", you need the aarch64 version. If it says "Intel", take x64. Oracle offers a .dmg file for both. The installer asks for your admin password and puts the JDK into /Library/Java/JavaVirtualMachines/. After that, the java and javac placeholders find it automatically, so you normally don't need a PATH entry.
2. Check which JDK is active
/usr/libexec/java_home -V
This command lists all installed JDKs. If yours doesn't show up, the installation didn't work.
3. Special case: Homebrew
If you installed the JDK with brew install openjdk, it doesn't land in the system folder. After installing, Homebrew shows a note with a sudo ln -sfn ... command that makes the JDK visible to the system placeholders. Run exactly that command, or set the PATH in your ~/.zshrc:
export JAVA_HOME=$(/usr/libexec/java_home) export PATH="$JAVA_HOME/bin:$PATH"
Then open a new Terminal window.
Test that everything works
Create a file called Main.java:
public class Main { public static void main(String[] args) { System.out.println("javac works!"); }}
Compile and run it in the same folder:
javac Main.java java MainOutput
javac works!
Important: when you run it, you type java Main, without .class. Since Java 11 you can also run small single-file programs directly with java Main.java, and Java compiles them in the background. For class and exams you should still know both steps.
If you now get errors like cannot find symbol or ';' expected, your setup is done. Those are real compiler errors in your code. What they mean is explained in The 10 most common Java error messages.
The fastest way out: practise today, set up later
Sometimes you simply don't have time for PATH and JDK tonight. Your next test is in four weeks, and you finally want to write code. Then you can put the setup off.
In Jario, Java runs in the browser. You need no JDK, no PATH and no admin rights, because the code runs on our server. "Run" starts main, and "Check" runs tests, for example "3 of 4 tests passed". The "What does this mean?" hint explains real compiler errors in plain language, and with "Explain the error" the AI tutor explains the error in your own code.
A good place to start is the article Input and output in Java, then conditions with if and else and later methods. Every topic comes with tasks and tests. You can solve the first two without an account.
If you have to work locally later, this guide is still here. More on starting without any setup is in Learn Java without installing anything. And if you use Eclipse on a Mac, Setting up Eclipse on a Mac will help.
In short
- "'javac' is not recognized" means the terminal can't find the compiler.
- Use
java -versionandjavac -versionto check whether a JDK is missing or just the PATH. - On Windows, the JDK's
binfolder belongs on the PATH, and afterwards you need a new terminal. - On a Mac, install the JDK that matches your chip, aarch64 or x64.
Related articles to learn
- Input and outputJava input and output explained simply: print values with println and printf, read numbers with Scanner. With examples and common mistakes.Read article
- ConditionsJava conditions with if, else if, switch, && and || explained clearly. With examples and the common mistakes that cost points in exams.Read article
- Methods and recursionJava methods explained simply: parameters, return, overloading, varargs and recursion with examples. Plus common mistakes like a missing return.Read article
More posts
- Getting startedBlueJ at homeSet up BlueJ at home or practise with no installation at all: what works on a family laptop, tablet or Chromebook and how to get ready for your next test.Read more
- Getting startedEclipse on a MacEclipse won't open on your Mac or can't find a JDK? The most common causes on Apple silicon and Intel Macs, solved, plus how to practise Java today anyway.Read more
- Getting startedJava without admin rightsJava without admin rights on a work laptop or school computer: which options are allowed, what works technically and how to practise every day anyway.Read more