Install Java on macOS
18 April 2022 (Updated 27 October 2024)
Install the openjdk
formula:
brew install openjdk
On installation, you’ll see some caveats. Make sure to read and follow instructions if necessary.
On Monterey 12.3, macOS appears to ship with a default Java, so you probably want to update your PATH
to have the executables provided by openjdk (e.g., java
, javac
, javadoc
) take precedence over any macOS defaults. You’ll want to add this to your .bashrc
, .zshrc
, or equivalent:
export PATH="/opt/homebrew/opt/openjdk/bin:$PATH"
Source the config file once you’ve added the above. Run:
source ~/.zshrc
Now, run which java
and you should see:
/opt/homebrew/opt/openjdk/bin/java
instead of the previous:
/usr/bin/java
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment