jenv

Table of contents
  1. Installation
  2. Typical usage
  3. Basic commands
    1. Add JDK
    2. List all added JDKs
    3. Set global JDK
    4. Set JDK for current working directory

Installation

brew install jenv
echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(jenv init -)"' >> ~/.zshrc
exec $SHELL -l
jenv enable-plugin export
exec $SHELL -l

Typical usage

First install the JDK you want to use,

brew install --cask corretto11

Then add it to jenv,

jenv rehash
jenv add "$(/usr/libexec/java_home)"
# Or if the following does not work
jenv add /Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home

Check that JDK has been added by,

$ jenv versions
* system
  11.0
  11.0.16.1
  corretto64-11.0.16.1

To set a JDK for current working directory,

jenv local 11.0  # OR 11.0.16.1 OR corretto64-11.0.16.1

Confirm that JAVA_HOME has been set,

echo ${JAVA_HOME}

Basic commands

jenv -h or jenv help <command> for more details.

Add JDK

jenv add ${PATH_TO_JVM_HOME}

List all added JDKs

jenv versions

Set global JDK

jenv global ${version_name_from_jenv_versions}

Set JDK for current working directory

jenv local ${version_name_from_jenv_versions}