Assuming brew is already installed and updated:

brew install openjdk@17

If using bash:

echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.bash_profile

Or using zsh (on macOS Catalina or newer), then it should be:

echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.zshrc

Restart your shell.

If you have multiple JDK versions installed, you can specify one, using -v flag:

echo export "JAVA_HOME=\$(/usr/libexec/java_home -v 17)" >> ~/.zshrc

Check the java version:

java --version

openjdk 17.0.2 2022-01-18
OpenJDK Runtime Environment (build 17.0.2+8-86)
OpenJDK 64-Bit Server VM (build 17.0.2+8-86, mixed mode, sharing)
Answer from Pri on Stack Overflow
Top answer
1 of 13
407

In 2024, even if you can use just brew..

Copybrew install openjdk@17 

Java will be installed here:

Copy/opt/homebrew/opt/openjdk@17/bin/java

for Apple Intel path is /usr/local/... rather than /opt/homebrew/...

For the system Java wrappers to find this JDK, symlink it with:

Copysudo ln -sfn /opt/homebrew/opt/openjdk\@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

resp. for Intel

Copysudo ln -sfn /usr/local/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

Now, running /usr/libexec/java_home -V should show the path to JAVA 17, something like:

Copy17.0.9 (x86_64) "Homebrew" - "OpenJDK 17.0.9" /opt/homebrew/Cellar/openjdk@17/17.0.9/libexec/openjdk.jdk/Contents/Home

(This is what you are missing btw, if javac or javac --version does not give you a command-not-found but an The operation couldn’t be completed. Unable to locate a Java Runtime.)

In case you see the wrong version, check if the path to JAVA_HOME is set correctly. If not, you could set it by:

Copyexport JAVA_HOME=\$(/usr/libexec/java_home)

...give a try to sdkman, it's far better than brew

Copycurl -s "https://get.sdkman.io" | bash

then open a new shell and try list to see what you could install ;-)

Copysdk list java 

At time of writing you could use:

Copysdk install java 17.0.4.1-tem

Java will be installed here:

Copy/Users/YOUR_USERNAME_HERE/.sdkman/candidates/java/17.0.4.1-tem
2 of 13
56

Java doesn't mind if you install multiple versions. This is often required; java is not backwards compatible (it tries to change little, but e.g. the java8 to java9 transition broke a ton of stuff, much of it needless and much of it not reasonably expectable or fixable by libraries and apps, so a bunch of java apps and libraries only run on java8 - just an example).

So, yes, you have installed JDK17. Also, yes, if you just run java without specifying which one you want, you so happen to get java13 here.

To see all installed javas, you can run:

Copy/usr/libexec/java_home -V

to 'override', you can use something like (depends on which shell you're using on your mac):

Copyexport JAVA_HOME=`/usr/libexec/java_home -v 17`

(the backticks mean: Run this then take the output of it and treat that as the 'value' of the expression. here, assign it to the JAVA_HOME env var. -v 17 requests a path to java 17. The -V option lists all and is meant for your eyeballs, not for scripts. The -v option is mostly for scripting, and that's how we're using it here).

JAVA_HOME decides which java is used by some things, but the java you get when you just type java is /usr/bin/java, and that executable is actually just a wrapper that picks a java to run from amongst all installed versions. It uses JAVA_HOME to decide which java to actually run. There are wrappers for all the common commands (javac, too). You can always run e.g. which javac to see what that actually runs; you probably see /usr/bin/javac. Everything in /usr/bin is one of these wrapper thingies that looks at JAVA_HOME and then runs the binary it finds there.

🌐
YouTube
youtube.com › watch
How to Install Java 17 On MacOS using Homebrew - openjdk | Mac M1 M2 | Intel or Silicon Based Mac - YouTube
In this video, I have explained how we can install java 17 on MacOS using homebrew. I have shown the install process for Macbook M1 which is silicon based sy...
Published   October 24, 2023
🌐
Java With Us
javawithus.com › home › faq › how to install java 17 on mac
How to Install Java 17 on Mac | Java With Us
April 21, 2026 - Install Java 17 on Mac via brew install openjdk@17, symlink it, and switch with java_home. Full steps for Apple Silicon and Intel.
🌐
YouTube
youtube.com › watch
How to Install Java 17 on Mac Using Brew and Set Up JAVA_HOME - YouTube
This guide provides step-by-step instructions for installing Java 17 on Mac using Homebrew and configuring the Java Home environment variable for optimal dev...
Published   April 6, 2025
Views   58
🌐
Medium
medium.com › @haroldfinch01 › step-by-step-guide-installing-and-switching-java-versions-on-mac-osx-f3896b9872f4
Step-by-Step Guide: Installing and Switching Java Versions on Mac OSX | by Harold Finch | Medium
May 21, 2024 - brew install openjdk@11 · Install Java 17 · brew install openjdk@17 · After installing each version, follow the instructions provided by Homebrew to add the Java versions to your PATH. jenv is a Java environment manager that makes it easy ...
🌐
YouTube
youtube.com › watch
✅ Solved - Download & install openjdk 17 on Mac OS (Sonoma, Sequoia, Ventura) via Homebrew / brew - YouTube
"In this video, we will show you how to download & install *openjdk 17* on Mac OS. * App name(s): openjdk 17 * Description of *openjdk 17* : _*Develop...
Published   January 6, 2025
Find elsewhere
🌐
Homebrew
formulae.brew.sh › cask › oracle-jdk@17
Homebrew Formulae: oracle-jdk@17
brew install --cask oracle-jdk@17 · Name: Oracle Java Standard Edition Development Kit · JDK from Oracle · https://www.oracle.com/java/technologies/downloads/ Development: Pull requests · Cask JSON API: /api/cask/oracle-jdk@17.json · Cask ...
🌐
CodingTechRoom
codingtechroom.com › question › install-jdk-17-mac-brew
How to Install JDK 17 on Mac Using Homebrew - CodingTechRoom
Wanting to utilize new features of JDK 17. Open your terminal application. Update Homebrew to the latest version: `brew update`. Install JDK 17 with the command: `brew install openjdk@17`.
🌐
TecAdmin
tecadmin.net › install-java-macos
How to Install JAVA on macOS – TecAdmin
April 26, 2025 - Follow the below steps to install the specific version of Java or all the available Java versions on your macOS system. Open a terminal and use brew to search available versions of Java ...
🌐
javaspring
javaspring.net › blog › brew-install-java-17
Mastering `brew install java 17` — javaspring.net
Using brew install openjdk@17 is a convenient way to install and manage Java 17 on your macOS or Linux system. Homebrew simplifies the installation process, and with the right post - installation setup and best practices, you can efficiently ...
🌐
Snyk
snyk.io › blog › install-java-on-macos
How to install Java on macOS | Snyk
April 17, 2024 - java -version openjdk version "17.0.9" 2023-10-17 OpenJDK Runtime Environment Homebrew (build 17.0.9+0) OpenJDK 64-Bit Server VM Homebrew (build 17.0.9+0, mixed mode, sharing) Finally, verify that OpenJDK is installed correctly by checking the Java version again: ... If OpenJDK is installed correctly, this command should display the version of OpenJDK you installed. And there you have it! You've successfully installed OpenJDK on macOS.
🌐
GitHub
gist.github.com › gwpantazes › 50810d5635fc2e053ad117b39b597a14
How to install different JDK versions on MacOS with Homebrew · GitHub
I recommend jEnv for switching between multiple Java environments on MacOS. I think it's generally wise to have homebrew/cask and homebrew/cask-versions tapped. They are practically core. SDKMAN is a SDK downloader and manager that can be a viable alternative to Homebrew for installing JDKs and even managing them. ... There has since been a change to the steps. I believe the recent ones I've come across are: $ brew tap homebrew/cask-versions $ brew cask install homebrew/cask-versions/adoptopenjdk8
🌐
Homebrew
formulae.brew.sh › formula › openjdk@17
Homebrew Formulae: openjdk@17
brew install openjdk@17 · Development kit for the Java programming language · https://openjdk.org/ License: GPL-2.0-only WITH Classpath-exception-2.0 · Development: Pull requests · Formula JSON API: /api/formula/openjdk@17.json · Formula ...
🌐
javathinking
javathinking.com › blog › installing-jdk17-on-mac-with-brew
Install JDK17 on Mac with Brew: Fix java_home Not Detecting JDK17 (While Managing Java 8, 11, 16) — javathinking.com
cat /Library/Java/JavaVirtualM... jenv versions to confirm. Installing JDK17 on macOS with Brew is straightforward, but java_home detection issues can arise due to non-standard installation paths....
🌐
Adam the Automator
adamtheautomator.com › install-java-on-mac
How to Install Java on Mac
November 30, 2022 - To install the latest version of Java on your Mac: 1. Run the below brew update command to update Homebrew.
🌐
DevQA
devqa.io › brew-install-java
How to Use Brew to Install Java on Mac
If not, you can install it via: $ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" If you already have brew installed, make sure you have the latest version by running the following command in a terminal
🌐
Java With Us
javawithus.com › home › faq › how to install java 17 on windows, mac and linux
How to Install Java 17 on Windows, Mac and Linux | Java With Us
April 21, 2026 - Install Java 17 LTS on any OS: winget or Temurin MSI on Windows, brew install openjdk@17 on Mac, apt install openjdk-17-jdk on Ubuntu.
🌐
Java With Us
javawithus.com › home › faq › how to install java on mac (homebrew + pkg)
How to Install Java on Mac (Homebrew + pkg) | Java With Us
April 21, 2026 - If javac -version fails, you installed a JRE instead of a JDK — rerun with the JDK option on adoptium.net or brew install openjdk@21 (Homebrew installs JDK by default). Install additional versions with brew install openjdk@17 etc., symlink each one, then switch with: