How to Install Java 17 on Mac

Java 17 is an LTS release still widely required by frameworks like Spring Boot 2.x and older Jakarta EE containers. On Mac, the cleanest install path is Homebrew.

Install via Homebrew

brew install openjdk@17

Homebrew installs to $(brew --prefix)/opt/openjdk@17. Create the symlink so /usr/libexec/java_home and IntelliJ find it:

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

Activate in the current shell:

export JAVA_HOME=$(/usr/libexec/java_home -v 17)
java -version   # should say 17.x

To make it the default permanently, add the export line to ~/.zshrc.

Install via Temurin .pkg

  1. Visit adoptium.net/temurin/releases, filter by Java 17, macOS, and your architecture (aarch64 or x64).
  2. Download the .pkg and double-click to install.
  3. Add to ~/.zshrc:
export JAVA_HOME=$(/usr/libexec/java_home -v 17)

List all installed JDKs

/usr/libexec/java_home -V

Output shows each detected JDK and its path.

Switch between 17 and 21

Add shell aliases to ~/.zshrc:

alias java17='export JAVA_HOME=$(/usr/libexec/java_home -v 17)'
alias java21='export JAVA_HOME=$(/usr/libexec/java_home -v 21)'

Then in a terminal, run java17 or java21 to switch for the current session.

Per-project switching with jenv

jenv reads a .java-version file in each project directory and switches automatically:

brew install jenv
echo 'eval "$(jenv init -)"' >> ~/.zshrc
source ~/.zshrc
jenv add $(/usr/libexec/java_home -v 17)
jenv add $(/usr/libexec/java_home -v 21)
# In a project directory:
jenv local 17.0.x   # creates .java-version