logo

How to install OpenJDK on macOS?

Posted on
Authors

Steps:

  1. Install OpenJDK using brew

    brew install openjdk
    
    brew install openjdk
    
  2. 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