sodcalculator

10 Tech How-To

Install Java on macOS: Easy Steps

Guide 10-55843 · Updated · Step by step

To install Java on macOS, you download the installer from Oracle or an OpenJDK distribution and run it, or use a package manager like Homebrew. This guide covers the current methods for Apple Silicon (M1/M2/M3) and Intel Macs, how to verify the installation, and how to manage multiple versions.

What Java Actually Is

Java is a programming language and a runtime platform. The thing you install is the Java Runtime Environment (JRE), which lets you run Java applications, or the Java Development Kit (JDK), which includes the JRE plus tools like the compiler (javac) and the archiver (jar). For most users who just want to run a program, the JRE is enough. For developers, the JDK is required. The JDK also includes the JRE, so installing the JDK covers both cases.

Since Oracle changed its licensing in 2019, the free version of Oracle’s JDK is only for development and personal use. For production or business use, you need a paid subscription. That is why many people now use OpenJDK builds, which are free and open-source. The most popular free builds include Eclipse Temurin (formerly AdoptOpenJDK), Amazon Corretto, and Azul Zulu. They all work the same way on macOS.

Check if Java Is Already Installed

macOS does not come with Java pre-installed since macOS 10.7 (Lion). If you previously installed it, you can check the version by opening Terminal (in Applications > Utilities) and typing:

java -version

If Java is installed, you will see output like:

openjdk version "21.0.2" 2024-01-16
OpenJDK Runtime Environment (build 21.0.2+13)
OpenJDK 64-Bit Server VM (build 21.0.2+13, mixed mode, sharing)

If not, macOS will show a message saying “No Java runtime present, requesting install” and may pop up a dialog that takes you to the Oracle download page. That dialog is not the only option; you can ignore it and use any of the methods below.

Method 1: Install with Homebrew (Recommended)

Homebrew is a package manager for macOS. If you already have Homebrew installed, this is the easiest way to install the latest OpenJDK:

  1. Open Terminal.
  2. Update Homebrew: brew update
  3. Install the latest OpenJDK: brew install openjdk

After installation, Homebrew will tell you that the JDK is not yet in the system Java path. You need to create a symbolic link so macOS can find it. Run these two commands:

sudo ln -sfn $(brew --prefix)/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

Then set the environment variables by adding these lines to your ~/.zshrc file (if you use zsh, which is the default since Catalina):

export JAVA_HOME=$(/usr/libexec/java_home)
export PATH="$JAVA_HOME/bin:$PATH"

Close and reopen Terminal, then verify with java -version.

If you need a specific version, you can install it with a formula like openjdk@17 or openjdk@11. Homebrew keeps older versions in separate directories, and you can switch between them using java_home or a tool like jenv.

Method 2: Download the Installer from Oracle or OpenJDK

If you prefer a graphical installer, go to the official download page for your chosen distribution. For Oracle JDK, go to oracle.com/java/technologies/downloads. For Eclipse Temurin, go to adoptium.net. Both offer macOS versions as a .dmg file.

  1. Download the .dmg file for macOS (choose the one for Apple Silicon if you have an M1/M2/M3 Mac, or x64 for Intel).
  2. Double-click the .dmg to mount it.
  3. Double-click the .pkg installer inside.
  4. Follow the prompts. The installer will put the JDK in /Library/Java/JavaVirtualMachines/.
  5. Close the installer and eject the disk image.

After that, open Terminal and run java -version to confirm. The installer automatically sets the system paths, so you do not need to edit any files.

How to Choose the Right Version

Java releases follow a predictable schedule: a new major version every six months, and a long-term support (LTS) version every two years. As of 2024, the LTS versions are Java 8, 11, 17, and 21. Java 21 is the latest LTS and is a good default for new projects. Java 8 is legacy but still used by many older applications.

If you are running a specific program, check its documentation for the required Java version. If you are developing, choose the LTS version your team uses. If you are just experimenting, the latest version (currently Java 22) is fine, but it will be superseded quickly.

You can have multiple versions installed side by side. macOS uses the /usr/libexec/java_home tool to manage them. To see all installed versions, run:

/usr/libexec/java_home -V

To set the JAVA_HOME for a specific version, use:

export JAVA_HOME=$(/usr/libexec/java_home -v 17)

Put that line in your shell profile to make it permanent.

Common Problems and Fixes

“Java is not recognized as an internal or external command” – This means the PATH is not set. After installing via Homebrew, make sure you added the export lines to your shell profile and restarted Terminal.

“Cannot execute binary file” – You downloaded the wrong architecture. Apple Silicon Macs (M1/M2/M3) need the aarch64 build, not the x64 one. Check your Mac’s chip by clicking the Apple menu > About This Mac.

“Unable to locate a Java Runtime” – This happens when you have the JRE but not the JDK, or when the JavaVirtualMachines folder is empty. Reinstall the JDK and make sure it appears in /Library/Java/JavaVirtualMachines/.

“Java is damaged and cannot be opened” – This is a Gatekeeper issue. Go to System Settings > Privacy & Security and click “Open Anyway” for the installer, or right-click the installer and select Open.

Uninstalling Java

To completely remove Java, delete the JDK folder and remove the symlinks. For a Homebrew install, run:

brew uninstall openjdk

For a manual installer, delete the folder in /Library/Java/JavaVirtualMachines/ (you will need admin rights). For example:

sudo rm -rf /Library/Java/JavaVirtualMachines/openjdk.jdk

Then remove any environment variables you added to your shell profile.

Frequently Asked Questions

Is Java free to install on macOS? Yes, the OpenJDK builds are completely free. Oracle’s JDK is free for personal use and development, but you need a paid subscription for production or business use.

Do I need Java on my Mac? Only if you run software that requires it, such as Minecraft, some business applications, or if you are a developer. Modern macOS does not include it by default, and most users never need it.

What is the difference between JRE and JDK? The JRE lets you run Java programs, while the JDK lets you create them. The JDK includes the JRE, so installing the JDK is the safer choice.

How do I update Java on macOS? For Homebrew, run brew upgrade openjdk. For manual installs, download the newer version and run the installer; it will replace the old one. You can also use /usr/libexec/java_home -V to see which versions are active.

Can I run multiple Java versions on my Mac? Yes, you can install several versions side by side. Use /usr/libexec/java_home -v to select one per terminal session, or use a version manager like jenv to automate switching.

Why does my Mac say “Java is not installed” even after I installed it? This usually means the PATH or JAVA_HOME is not set correctly. Check that the JDK is in /Library/Java/JavaVirtualMachines/ and that your shell profile points to the right directory.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →