How to install OpenJDK on macOS?
- Posted on
- Authors
- Name
- ansidev
- @ansidev
Steps:
Install OpenJDK using brew
brew install openjdk
brew install openjdk
Configure environment variable
JAVA_HOME
.Configure manually:
Add the below line to
~/.zshrc
:export JAVA_HOME="/usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home"
export JAVA_HOME="/usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home"
Restart your terminal.
Or you can run the below command:
echo -e "\nexport JAVA_HOME=\"$(brew --prefix openjdk)/libexec/openjdk.jdk/Contents/Home\"" >> ${ZDOTDIR:-~}/.zshrc && exec zsh
echo -e "\nexport JAVA_HOME=\"$(brew --prefix openjdk)/libexec/openjdk.jdk/Contents/Home\"" >> ${ZDOTDIR:-~}/.zshrc && exec zsh