sajad torkamani

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

Leave a comment

Your email address will not be published. Required fields are marked *