Java on Mac requires downloading from Oracle or using a package manager like Homebrew
Installing Java on Mac means getting the Java Development Kit (JDK) — the software that lets your computer run and write Java programs. You have two main routes: download directly from Oracle's website, or use Homebrew, a package manager that handles the download and setup automatically. Most people find Homebrew faster because it handles file paths and environment variables without manual configuration.
Before you start, check whether Java is already on your Mac. Open Terminal (find it in Applications > Utilities) and type java -version. If you see a version number, Java is installed. If you see "command not found", you need to install it.
Key Takeaways
- Homebrew is the fastest route for most people because it installs Java and sets up your system paths automatically.
- If you prefer not to use Homebrew, download the JDK directly from Oracle's website and follow the installer prompts.
- After installation, verify Java works by typing java -version in Terminal to see the version number.
- You may need to set the JAVA_HOME environment variable if you plan to use Java with build tools like Maven or Gradle.
Installing Java with Homebrew (the faster route)
Homebrew is a package manager that downloads software and puts it in the right places on your Mac automatically. If you don't have Homebrew yet, install it first by opening Terminal and pasting this line:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Once Homebrew is installed, type this command to install Java:
brew install openjdk
Homebrew downloads OpenJDK (a free version of Java) and installs it. When it finishes, type java -version to confirm it worked. You should see a version number like "openjdk version 21.0.1" or similar.
Installing Java directly from Oracle
If you prefer to download Java yourself rather than use Homebrew, go to oracle.com/java/technologies/downloads. Look for the macOS section and choose the version for your Mac's processor — Apple Silicon (M1, M2, M3 chips) or Intel.
Download the .dmg file (the installer). Double-click it to open the installer window, then double-click the package icon inside. Follow the prompts and enter your Mac password when asked. The installer puts Java in a standard location on your system.
When installation finishes, open Terminal and type java -version to confirm it worked.
Setting JAVA_HOME if you use build tools
If you plan to use Maven, Gradle, or other build tools with Java, you may need to set an environment variable called JAVA_HOME. This tells those tools where Java lives on your computer.
Open Terminal and type echo $JAVA_HOME. If it returns a path (something like /Library/Java/JavaVirtualMachines/openjdk-21.jdk/Contents/Home), it's already set. If it returns nothing, you need to add it.
To set JAVA_HOME, open Terminal and type:
nano ~/.zshrc
This opens a text editor. Add this line at the end:
export JAVA_HOME=$(/usr/libexec/java_home)
Press Control+X, then Y, then Enter to save. Close Terminal and open it again. Type echo $JAVA_HOME to confirm the path now appears.
Choosing between OpenJDK and Oracle JDK
OpenJDK (installed via Homebrew) and Oracle JDK are both free and work the same way for most projects. OpenJDK is simpler to install and update because Homebrew handles everything. Oracle JDK is the official version from the company that maintains Java, and some organizations prefer it for that reason.
For learning Java or personal projects, OpenJDK is the better choice. For work projects, check whether your team or company has a preference.
Updating Java when a new version comes out
If you installed Java with Homebrew, type brew upgrade openjdk to get the latest version. If you installed Oracle JDK directly, visit oracle.com/java/technologies/downloads periodically and download the new version — the installer replaces the old one automatically.
You can have multiple Java versions on your Mac at the same time. To switch between them, use the command /usr/libexec/java_home -V to see all installed versions, then set JAVA_HOME to the one you want.
Troubleshooting common installation problems
If you see "command not found" after installation, Java didn't install or your system doesn't know where it is. Try closing Terminal completely and opening it again — sometimes the system needs to reload. Then type java -version again.
If Homebrew says it can't install Java, your Mac may need updates. Type brew doctor to see what Homebrew recommends. If you're installing Oracle JDK and the installer won't open, right-click the .dmg file and select "Open" — this bypasses a security check for unsigned installers.
If you get an error about Java not being found when you try to run a program, the program may be looking for JAVA_HOME. Follow the steps in the "Setting JAVA_HOME" section above to fix it.
Frequently Asked Questions
Do I need to install Java if I just want to run Java programs?
Yes. Running Java programs requires the Java Runtime Environment (JRE), which comes with the JDK. If you only want to run programs and never write code, you can install just the JRE instead, but the JDK is simpler and includes everything you need.
Can I have both OpenJDK and Oracle JDK installed at the same time?
Yes. Your Mac can hold multiple Java versions. Use /usr/libexec/java_home -V to see all installed versions and switch between them by changing JAVA_HOME.
What's the difference between Java 17, Java 21, and other version numbers?
Java releases a new major version every six months. Version 21 is newer than version 17. For learning, either works fine. For work projects, check whether your team requires a specific version — some organizations stick with older versions for stability.
Why does my IDE say Java is not installed when I just installed it?
Your IDE (like IntelliJ or Eclipse) may not have reloaded after installation. Close the IDE completely, then reopen it. If it still doesn't find Java, go to the IDE's settings and point it manually to your Java installation path.
Is it safe to delete the Java installer after installation finishes?
Yes. Once Java is installed, you don't need the .dmg file or installer anymore. You can move it to Trash.