Skip to content

Instantly share code, notes, and snippets.

@Starraider
Last active September 11, 2020 14:50
Show Gist options
  • Save Starraider/e3a8dbf7cac95556400559946694bedb to your computer and use it in GitHub Desktop.
Save Starraider/e3a8dbf7cac95556400559946694bedb to your computer and use it in GitHub Desktop.
How to manage your Java environments in MacOS

How to manage your Java environments in MacOS

If you are a developer you need sometimes a diferent version of the JDK. MacOS comes also with his own JDK. So, how can you manage all the installed JDKs?

jEnv

jEnv is a command line tool to help you forget how to set the JAVA_HOME environment variable.

Installation and Setup

Install it:

brew install jenv

To set it up execute the following commands at the command line:

export JENV_ROOT=/usr/local/opt/jenv
echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(jenv init -)"' >> ~/.zshrc

Search for your JDKs. Usually they are in /Library/Java/JavaVirtualMachines/
Add all the JDKs to jenv:

jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home

List managed JDKs

$ jenv versions
  system
  oracle64-1.6.0.39
* oracle64-1.7.0.11 (set by /Users/hikage/.jenv/version)

Configure global version

$ jenv global oracle64-1.6.0.39

Configure local version (per directory)

$ jenv local oracle64-1.6.0.39

Configure shell instance version

$ jenv shell oracle64-1.6.0.39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment