Installing Java on macOS

Java Development Kit (JDK) and Java Runtime Environment (JRE)

For some time now, Java is not (pre-)installed anymore, let’s fix that. As I'm writing this, Java 22 is the latest version. JDK 22 reached General Availability on 19 March 2024. (Use 21 for long term support)and Adoptium is one of the best places to find Prebuilt OpenJDK Binaries.

Adoptium was known as AdoptOpenJDK, before the project was moved to the Eclipse Foundation. All available versions for supported platforms can be found here.

If you are already using Homebrew then the easiest way to get the JDK on to your Mac might be this:

$brew install --cask temurin

# Install a specific version
$brew tap homebrew/cask-versions
$brew install --cask temurin11

# Uninstall a specific version
$brew uninstall --cask temurin

Otherwise, the easiest way is to select macOS aarch and OpenJDK 22, download and install the pkg file.

Like you can see, the package installer will put the JDK into this location: /Library/Java/JavaVirtualMachines/temurin-22.jdk/

Almost done. After opening a terminal, the successful installation of the JDK can be confirmed like so:

java --version

... hopefully showing something like this:

openjdk 22.0.1 2024-04-16
OpenJDK Runtime Environment Temurin-22.0.1+8 (build 22.0.1+8)
OpenJDK 64-Bit Server VM Temurin-22.0.1+8 (build 22.0.1+8, mixed mode)

JAVA_HOME is an important environment variable and it’s important to get it right. Here is a trick that allows me to keep the environment variable current, even after a Java Update was installed. In ~/.zshenv, I set the variable like so:

export JAVA_HOME=$(/usr/libexec/java_home)

Open a new terminal and verify:

echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/temurin-22.jdk/Contents/Home

Source Code

The source code of the Java Platform, Standard Edition 22 Reference Implementations is available on github

API Specification (Java Doc)

The API Specification of the Java Platform, Standard Edition and Java Development Kit can be found here: