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.

🌐
Apple Support
support.apple.com › en-us › 106567
Java for Mac OS X 10.6 Update 17 - Apple Support
Java for Mac OS X 10.6 Update 17 delivers improved security, reliability, and compatibility by updating Java SE 6 to 1.6.0_65.
Discussions

How to set or change the default Java (JDK) version on macOS? - Stack Overflow
How can you change the default version of Java on a mac? More on stackoverflow.com
🌐 stackoverflow.com
How to update my Java from 17 to 22?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
19
5
May 6, 2024
How to install Java?
I think the first command will install the LTS version, which is currently 11. This has always been confusing on Debian distros. Are you just running java? Or are you looking to build new java code? Install the jdk if you want to build, not the jre. More on reddit.com
🌐 r/pop_os
4
5
February 25, 2020
How do I change the default version of Java that Curse uses to launch Minecraft?
You can't, it will download it again and again and again, I tricked it out by deleting the content of the folder located in Your documents folder\Curse\Minecraft\Install\runtime\jre-x64\1.8.0_25 delete the entire content of this folder not the folder itself and do not rename it cause it would redownload it again, just replace the content with the content of the folder located here : C:\Program Files\Java\jre1.8.0_91 This will trick the game and it works, but I got back to using MultiMC instead, Curse isn't good performance wise, only good for keeping mods up to date, and even sometimes its not up to date either. More on reddit.com
🌐 r/feedthebeast
9
2
May 23, 2016
🌐
Oracle
java.com › en › download › help › mac_java_update.html
How do I Update Java for my Mac?
Go to the Update tab in Java Control Panel and click on Update Now button that brings up Installer window. Click on Install Update. Click on Install and Relaunch. Save all your work before clicking Install and Relaunch. Once the installation is completed the Java application will be relaunched.
🌐
Se-education
se-education.org › guides › tutorials › javaInstallationMac.html
Java 17 Installation Guide for Mac Users
This guide explains how to install the (specifically, Java 17 JDK+FX Azul distribution) on macOS using SDKMAN. ... This version comes with (which is not included in most ).
🌐
Medium
medium.com › @anuragchitti1103 › update-java-jdk-version-for-mac-silicon-f0df6b3d1cb7
Update Java JDK version for MAC Silicon - Anurag Chitti - Medium
February 29, 2024 - Update Java JDK version for MAC Silicon Here are a few simple steps for updating the JDK version using HomeBrew. brew install openjdk@17 Java will be installed …
🌐
Oracle
oracle.com › java › technologies › javase › jdk17-archive-downloads.html
Java Archive Downloads - Java SE 17.0.12 and earlier
The archive downloads for JDK 17 updates 17.0.13 and greater are offered under different license terms, and can be found here. The JDK is a development environment for building applications using the Java programming language. The JDK includes tools useful for developing and testing programs written in the Java programming language and running on the JavaTM platform. WARNING: Older versions of the JDK are provided to help developers debug issues in older systems.
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › install › installation-jdk-macos.html
5 Installation of the JDK on macOS - Java
April 21, 2026 - /Library/Java/JavaVirtualMachines/jdk-17.interim.update.patch.jdk · For example, to uninstall 17 Interim 0 Update 0 Patch 0: ... This topic provides answers for the following frequently asked questions about installing JDK on macOS computers. 1. How do I find out which version of Java is the system default?
Find elsewhere
🌐
Medium
medium.com › miro-engineering › how-to-switch-between-java-lts-versions-8-11-and-17-on-mac-cb6717d1272
How to switch between Java LTS versions 8, 11, and 17 on Mac | by Lothar Schulz | Miro Engineering | Medium
November 25, 2021 - # version 17 brew install openjdk@17 sudo ln -sfn /usr/local/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk# version 11 brew install openjdk@11 sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk ...
🌐
Medium
medium.com › java-mvp › guide-setting-up-and-switching-between-java-11-and-17-on-macos-9caff4c96e2d
Guide: Setting Up and Switching between Java 11 and 17 on macOS | by datatec.studio | Java MVP | Medium
November 25, 2023 - sudo rm -rf /Library/Developer/CommandLineTools sudo xcode-select --install /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" brew install openjdk@17 # The latest version openjdk 17.0.8.1 2023-08-24 ...
🌐
javathinking
javathinking.com › blog › jdk-17-install-mac
Installing JDK 17 on macOS: A Comprehensive Guide — javathinking.com
Use which java to check the active JDK path. Use SDKMAN! or jenv to switch to the desired version. ... Avoid using sudo with Homebrew—it can cause permission problems. For manual installs, ensure you have admin rights (enter your password when prompted). Installing JDK 17 on macOS is straightforward with multiple methods to suit your needs.
🌐
javathinking
javathinking.com › blog › what-is-the-best-way-to-update-java-version-on-mac-computer
How to Update Java Version on Mac: Best Methods (Brew, Web, & Alternatives) — javathinking.com
First, confirm which Java version is installed on your Mac. Open Terminal (Applications > Utilities > Terminal) and run: ... openjdk version "17.0.8" 2023-07-18 OpenJDK Runtime ...
🌐
javaspring
javaspring.net › blog › installing-java-17-on-mac
Installing Java 17 on Mac: A Comprehensive Guide — javaspring.net
If you installed using the Oracle JDK package, check the Oracle website for updates and download and install the latest version. Using a version manager like jenv allows you to easily switch between different Java versions. This is useful when you are working on multiple projects that require different Java versions. Installing Java 17 on a Mac is a straightforward process, whether you choose to use Homebrew or the Oracle JDK installation package.
🌐
Oracle
java.com › en › download › help › java_mac.html
Installing and using Oracle Java on macOS
Upgrading to the latest version of Java ensures that Java applications will run with the most up-to-date security and performance improvements on your system. If installing an older version of Java is absolutely required, you must first uninstall the current version. See the instructions at Mac uninstall Java FAQ. Why will applets not run after getting Java through Apple Software Update?
🌐
javaspring
javaspring.net › blog › java-17-download-mac
Java 17 Download and Installation on Mac: A Comprehensive Guide — javaspring.net
There are several ways to download Java 17 on a Mac: Open your web browser and go to the Adoptium website. On the Adoptium homepage, select the Java version as 17.
🌐
Lotharschulz
lotharschulz.info › 2021 › 11 › 30 › how-to-switch-between-java-lts-versions-8-11-and-17-on-mac
How to switch between Java LTS versions 8, 11 and 17 on Mac – Lothar Schulz
Some of my previous attempts are based on Big Sur 11 (e.g. https://www.lotharschulz.info/2021/01/11/change-default-java-version-on-macos-11-bigsur-persist-it/) . However, I can’t really help with your Mojave apart from upgrading the OS 😉 . ... Turns out that adoptopenjdk offer brew installation of prebuilt binaries, which avoids the need for compilation. I was able to install java 17 on Mojave with brew install — cask temurin (adoptopenjdk has been renamed temurin).
🌐
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 - Step-by-Step Guide: Installing and Switching Java Versions on Mac OSX To install Java on macOS and allow for easy switching between different versions, you can use a version manager like jenv. Here's …
🌐
Stony Brook University
www3.cs.stonybrook.edu › ~amione › CSE114_Course › materials › resources › InstallingJava17.pdf pdf
Installing Java 17 Downloading
To install the latest version of Java, go to the download site at Oracle.com. Scroll down to Java SE Development Kit 17.0.2 downloads. Click on the appropriate platform ... For mac, use the x76 DMG installer.
🌐
Mac Install Guide
mac.install.guide › java › update
Update Java on Mac · Mac Install Guide · 2026
Why update Java on macOS. How to upgrade Java on Mac. Update Java versions using Homebrew or installers. How to check and verify updates.
🌐
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 - sudo apt update sudo apt install openjdk-17-jdk java -version · sudo dnf install java-17-openjdk-devel java -version · sudo pacman -S jdk17-openjdk sudo archlinux-java set java-17-openjdk · Install both JDKs. On macOS, /usr/libexec/java_home -v 17 or -v 21 points at the right installation.
Top answer
1 of 16
2562

First run /usr/libexec/java_home -V which will output something like the following:

Matching Java Virtual Machines (3):
1.8.0_05, x86_64:   "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home
1.6.0_65-b14-462, x86_64:   "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
1.6.0_65-b14-462, i386: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home

Pick the version you want to be the default (1.6.0_65-b14-462 for arguments sake) then:

export JAVA_HOME=`/usr/libexec/java_home -v 1.6.0_65-b14-462`

or you can specify just the major version, like:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

Now when you run java -version you will see:

java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

Add the export JAVA_HOME… line to your shell’s init file.

For Bash (as stated by antonyh):

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

For Fish (as stated by ormurin)

set -x JAVA_HOME (/usr/libexec/java_home -d64 -v1.8)

Updating the .zshrc file should work:

nano ~/.zshrc

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8.0)

Press CTRL+X to exit the editor Press Y to save your changes

source ~/.zshrc
echo $JAVA_HOME
java -version
2 of 16
608

This answer is an attempt to address: how to control java version system-wide (not just in currently running shell) when several versions of JDK are installed for development purposes on macOS El Capitan or newer (Sierra, High Sierra, Mojave). As far as I can tell, none of the current answers do that (*).

As a developer, I use several JDKs, and I want to switch from one to the other easily. Usually I have the latest stable one for general use, and others for tests. But I don't want the system (e.g. when I start my IDE) to use the latest "early access" version I have for now. I want to control system's default, and that should be latest stable.

The following approach works with Java 7 to 12 at least (early access at the time of this writing), with Oracle JDK or OpenJDK (including builds by AdoptOpenJDK produced after mid-October 2018).

Solution without 3rd party tools:

  • leave all JDKs at their default location, under /Library/Java/JavaVirtualMachines. The system will pick the highest version by default.
  • To exclude a JDK from being picked by default, rename its Contents/Info.plist to Info.plist.disabled. That JDK can still be used when $JAVA_HOME points to it, or explicitly referenced in a script or configuration. It will simply be ignored by system's java command.

System launcher will use the JDK with highest version among those that have an Info.plist file.

When working in a shell with alternate JDK, pick your method among existing answers (jenv, or custom aliases/scripts around /usr/libexec/java_home, etc).


Details of investigation in this gist.


(*) Current answers are either obsolete (no longer valid for macOS El Capitan or Sierra), or only address a single JDK, or do not address the system-wide aspect. Many explain how to change $JAVA_HOME, but this only affects the current shell and what is launched from there. It won't affect an application started from OS launcher (unless you change the right file and logout/login, which is tedious). Same for jenv, it's cool and all, but as far as I can tell it merely changes environment variables, so it has the same limitation.