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
Answer from freedev 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.

🌐
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 ...
Discussions

How to choose between multiple JDK's on MacOS?
I have used sdkman - you can use it to manage your sdks like java, Scala, groovy More on reddit.com
🌐 r/java
30
22
August 29, 2021
Installing JDK on a new mac

I'd recommend homebrew for package management in general and sdkman for java (and related ecosystem) development tools.

More on reddit.com
🌐 r/java
17
21
December 8, 2017
HOW DO YOU DOWNLOAD AND USE JAVA 17?
If you download the installer that usually comes in a msi installer it should then Autodetect it. More on reddit.com
🌐 r/PrismLauncher
14
19
June 22, 2023
Oracle released native Apple Silicon Java JDK 17

Not sure when Open JDK released it, but it's there too https://jdk.java.net/17/

[ edit ] It was released on August 7th this year.https://openjdk.java.net/jeps/391 [/ edit ]

More on reddit.com
🌐 r/MacOS
13
50
September 22, 2021
🌐
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 - Install Java 8 · brew install openjdk@8 · Install Java 11 · 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.
🌐
Besu-eth
docs.besu-eth.org › how to › install and update java
Install and update Java | Besu documentation
1 month ago - To update Java on Ubuntu, uninstall the current versions and follow the instructions to install Java on Ubuntu with your target version. If you started with this guide, you can uninstall Java using the following command: ... You can update Java on MacOS using Homebrew.
🌐
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:
🌐
GitHub
github.com › orgs › Homebrew › discussions › 1594
'brew install openjdk' install jdk 17 but shows version as 16. How to install openjdk 16? · Homebrew · Discussion #1594
How can I install openjdk 16 ? ... $ java -version openjdk version "17" 2021-09-14 OpenJDK Runtime Environment Homebrew (build 17+0) OpenJDK 64-Bit Server VM Homebrew (build 17+0, mixed mode) OR $ /usr/libexec/java_home -V Matching Java Virtual Machines (1): 17 (arm64) "Homebrew" - "OpenJDK 17" /opt/homebrew/Cellar/openjdk/16.0.1/libexec/openjdk.jdk/Contents/Home /opt/homebrew/Cellar/openjdk/16.0.1/libexec/openjdk.jdk/Contents/Home
🌐
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 ...
Find elsewhere
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › install › installation-jdk-macos.html
5 Installation of the JDK on macOS - Java
April 21, 2026 - If you attempt to install jdk-17.0.1 after jdk-17 is installed, the installer uninstalls jdk-17 and installs jdk-17.0.1. Note:If you install an older version of a JDK when the newer version of the same feature family already exists, an error is displayed, prompting you to uninstall a newer JDK version if an older version has to be installed. JDK is installed in /Library/Java/JavaVirtualMachines/jdk-<FEATURE>.jdk where <FEATURE> is the feature release number.
🌐
Homebrew
formulae.brew.sh › formula › openjdk
Homebrew Formulae: openjdk
brew install openjdk · Also known as: java, openjdk@26 · 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: ...
🌐
Mac Install Guide
mac.install.guide › java › brew-cask
Brew Install Java - Easy Cask Method · 2026
Brew install Java on Mac. One command to install the recommended Temurin JDK. The cask method without PATH or symlink configuration. How to fix common Homebrew Java issues.
🌐
Reddit
reddit.com › r/java › how to choose between multiple jdk's on macos?
r/java on Reddit: How to choose between multiple JDK's on MacOS?
August 29, 2021 -

On MacOS, you can run /usr/libexec/java_home to get the current JDK MacOS will use...

On my system, it's:

OpenJDK Runtime Environment Zulu16.32+15-CA (build 16.0.2+7)

But, I have multiple JDK's installed:

/usr/libexec/java_home -V

Matching Java Virtual Machines (2):

16.0.2 (arm64) "Azul Systems, Inc." - "Zulu 16.32.15" /Library/Java/JavaVirtualMachines/zulu-16.jdk/Contents/Home

16.0.2 (x86_64) "Oracle Corporation" - "Java SE 16.0.2" /Library/Java/JavaVirtualMachines/jdk-16.0.2.jdk/Contents/Home

Does anyone know how (if I can) switch what MacOS will use by default?

So far, if I delete the current default, it'll switch to the one remaining (I've tried this my moving the current JDK to /tmp). But is there a more elegant way to do this?

🌐
Tutorials24x7
tutorials24x7.com › java › how-to-install-openjdk-17-on-mac
How To Install OpenJDK 17 On Mac | Tutorials24x7
September 26, 2021 - The default location used by macOS to search for the available JDK is - /Library/Java/JavaVirtualMachines. We can use the below-mentioned command to find the available JDKs installed on the system. ... It will list down the available JDKs as shown in Fig 4. ... Now, install the OpenJDK downloaded in the previous step using the commands as shown below. # Move to the download location cd ~/Downloads # Check the downloaded file name using ls -la command # Extract the download tar -xf openjdk-17_macos-x64_bin.tar.gz # Check the OpenJDK version using the list command # Output of ls -la command on my system total 722256 drwx------@ 7 catalina staff 224 Sep 26 07:05 .
🌐
Oracle
java.com › en › download › apple.jsp
Download Java
» Java 是什么 » 删除旧版本 » Mac 常见问题 » 安全性 » Support » 其他帮助 · 此下载用于帮助那些需要使用 Java 在台式机和笔记本电脑上运行应用程序的最终用户。Java 8 与操作系统集成在一起以运行单独安装的 Java ...
🌐
YippeeCode
yippeecode.com › topics › upgrade-to-openjdk-temurin-using-homebrew
Upgrade to OpenJDK Temurin using Homebrew - YippeeCode
November 16, 2021 - Upgrade to OpenJDK Temurin 17 LTS by Eclipse. This time I will get it from a new source since the AdoptOpenJDK repository is now deprecated. The command to install is very simple. ... To use a different version of Java, you need to activate a third-party repository (TAP). brew tap homebrew/cask-versions brew install --cask temurin8
🌐
Homebrew
formulae.brew.sh › cask › semeru-jdk-open@17
semeru-jdk-open@17 — Homebrew Formulae
brew install --cask semeru-jdk-open@17 · Name: IBM Semeru Runtime (JDK 17) Open Edition · Production-ready JDK with the OpenJDK class libraries and the Eclipse OpenJ9 JVM · https://developer.ibm.com/languages/java/semeru-runtimes · Development: ...
🌐
The Bored Dev
theboreddev.com › how-to-use-homebrew-in-mac-osx
How To Use Homebrew In Mac (OSX) » The Bored Dev
November 22, 2022 - Even if you are not sure about its name, most of the times Homebrew will suggest the right formula for you! Let’s install Java using brew, the command line executable that Homebrew provides.
🌐
Homebrew
formulae.brew.sh › formula › openjdk@8
Homebrew Formulae: openjdk@8
brew install openjdk@8 · Development kit for the Java programming language · https://openjdk.org/ License: GPL-2.0-only · Development: Pull requests · Formula JSON API: /api/formula/openjdk@8.json · Formula code: openjdk@8.rb on GitHub ...
🌐
Dhrimov
dhrimov.dev › blog › post › manage_several_java_versions_on_macos
Manage several Java versions on MacOS | Dmytro Hrimov
brew install --cask temurin@8 brew install --cask temurin@11 brew install --cask temurin@17 brew install --cask temurin@21 · After installing the Java versions, you'll need to configure your shell to switch between them easily.
🌐
Liquid Web
liquidweb.com › home › 10 steps to install java on windows, ubuntu, and macos
Simple Steps to Install Java on Ubuntu, Windows, and macOS | Liquid Web
January 15, 2026 - Once you have inserted JAVA_HOME=”/usr/lib/jvm/jdk-17/” into the last line of the file, use the :wq command to save and quit the file. Apply the file changes with the source command. ... To test that the Environment Variable is set correctly, use the following command. ... The system returns the appropriate location if done properly. ... Run the java -version command again to confirm Java is installed.
🌐
Justinjbird
justinjbird.com › home › blog › install apache spark on macos using homebrew
Install Apache Spark on macOS using Homebrew
You can install Java using Homebrew by running the following command in terminal: arch -arm64 brew install openjdk@17 # or run this on non-Mx Macs: brew install openjdk@17