Macos Java Home Intellij Jdk Mac
Installing OpenJDK on MacOS is easy with HomeBrew. If you haven’t got HomeBrew installed, install HomeBrew by running:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/nitin.katkam/.zprofile
Then, install OpenJDK with:
brew install java
Define environment variables with:
echo 'export PATH="/opt/homebrew/opt/openjdk/bin:$PATH"' >> ~/.zshrc
echo 'export JAVA_HOME=/opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home'
Download Apache Maven from: https://dlcdn.apache.org/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz and define the M2_HOME and PATH variables to the extracted path and to the bin subdirectory.
The /opt/homebrew/opt/openjdk/ seems like the Java Home directory but because IntelliJ looks for a different JDK directory structure, it complains with a “The selected directory points to a JRE not a JDK”, so we instead specify the path in the ./libexec/openjdk.jdk/Contents/Home instead.
Open a Java project with IntelliJ, and from the File menu, select Project Structure.
{:class=“img-responsive”}
In the popup dialog box, press Cmd+Shift+G to specify an absolute path and enter: /opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home
{:class=“img-responsive”}
Other Notes
Turns out that there’s an executable named java_home
that gives us the correct JAVA_HOME
path.
export JAVA_HOME=`/usr/libexec/java_home -v 19.0.1`
Also, brew info openjdk
provides an alternate approach:
brew info openjdk # This gives the following command to run (within the output)
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk