Skip to content

Jenv

In order to manage the multiple JDKs that you might have on your system, and to also properly set JAVA_HOME, we strongly suggest that you install the jenv utility.

Install Jenv

brew install jenv

Configure Jenv

Register all the JDKs that you might have on your system into jenv:

jenv add /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home/
...

Set your global JDK version:

jenv global 17.0

Enable the export plugin:

jenv enable-plugin export

Modify your bash profile

vi ~/.zshrc

Add these lines:

export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"

Verify JAVA_HOME

Open a new shell so your recent changes will be taken into account. Run this:

echo $JAVA_HOME
ls -ls $(echo $JAVA_HOME)

You should see something similar to:

/Users/cedar-dev/.jenv/versions/17.0
/Users/cedar-dev/.jenv/versions/17.0 -> /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home