Skip to content

Instantly share code, notes, and snippets.

@jgogstad
Created November 11, 2021 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgogstad/238bee9277e650b0492f3062ac62001f to your computer and use it in GitHub Desktop.
Save jgogstad/238bee9277e650b0492f3062ac62001f to your computer and use it in GitHub Desktop.
JVM management on macOS: Jabba and jEnv
  • Jabba: Manage JVMs installations
  • jEnv: What JVM to use in shell/global/local directory.

jEnv supports automatically changing JVMs based on current working directory

Installation

brew install jabba
brew install jenv
jenv init >> ~/.zshrc

# export plugin sets JAVA_HOME variable properly, both for shell and OS-level
jenv enable-plugin export

Install JVM

# This will update the local PATH variable, close shell after new JVM install
jabba install openjdk@1.14.0
jabba ls
jenv add ~/.jabba/jdk/openjdk@1.14.0/ # Adds 14, 14.0, 14.0.1 and openjdk@1.14.0

# Use JDK whenever entering this directory (writes `.jenv` file)
jenv local 14

# Use JDK for this shell only
jenv shell 14

# Change global JDK
jenv global 14

Caveats

Observed: 2020-05-28: By default jenv will point to version "system" and

echo $JAVA_HOME
/Users/jostein.gogstad/.jenv/versions/system

This directory doesn't exists. You need to either

jenv global 11

or

ln -s wherever-system-jdk-lives ~/.jenv/versions/system
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment