I'd like to setup java on a new OS X machine, and prefer to use brew for OS X package management. How can I install latest java using brew?

2 Answers

Turns out java has been moved into brew core recently, so the correct command as of January 2021 is:

brew install java 

Don't be like me and follow old instructions to install from cask, it will not work. You will get an error message from brew like this:

% brew install --cask java Error: Cask 'java' is unavailable: No Cask with this name exists. 

You may also see this:

% brew cask install java Error: Calling brew cask install is disabled! Use brew install [--cask] instead. 
7

As an add-on to the accepted answer: to install a certain version of Java, e.g. version 11, run:

brew install openjdk@11 

And symlink it:

sudo ln -sfn /opt/homebrew/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy