Setup: Install the Java 25 JDK

Install the Java Development Kit (Eclipse Temurin 25) and set JAVA_HOME on your Mac.

Novice · Operating System · Java · Updated

By

After this lesson you can

  • Install a JDK and check the versions of java and javac
  • Set the JAVA_HOME environment variable

macOS only. The Java Development Kit (JDK) contains everything you need to build and run Java programs. It includes javac, which compiles your code, and java, which runs it.

We use Java 25, a long-term support (LTS) release, in the Eclipse Temurin build. Temurin is a free build of Java from the Eclipse Foundation.

Install the JDK

brew install --cask temurin@25

Enter your Mac password when asked.

Check your work

Run:

java -version
javac -version

java -version prints three lines. The first starts with openjdk version "25, and the second names Temurin-25. javac -version prints javac 25 followed by more numbers. The numbers after 25 change with each update, so yours may differ from the ones shown here. The important parts are 25 and Temurin.

Set JAVA_HOME

Some tools, such as the Maven build tool you will use later, look for Java in a setting called JAVA_HOME. An environment variable is a named value that every program started from your terminal can read.

macOS can find the folder where Java 25 is installed. Add a line to your terminal's settings file that does that every time a terminal opens:

echo 'export JAVA_HOME=$(/usr/libexec/java_home -v 25)' >> ~/.zshrc

Close the Terminal window, open a new one, and run:

echo $JAVA_HOME

You should see a path that ends in temurin-25.jdk/Contents/Home.

Common problems

What you see What to do
java -version shows an older version, such as 17 or 21 Another JDK is installed too. Make sure you set JAVA_HOME above, then open a new terminal window. With JAVA_HOME set, java uses Java 25.
Unable to locate a Java Runtime The install did not finish. Run the brew install command again.
echo $JAVA_HOME prints an empty line You ran it in a window that was open before you changed ~/.zshrc. Open a new terminal window and try again.