Java environment - jEnv

If you develop on a computer with Linux or macOS, you might consider using jEnv, an open source Java environment management tool. This is a command-line tool, so do not expect a GUI. You can download the tool at this URL--https://github.com/gcuisinier/jenv.

Here is the installation command for Linux:

$ git clone https://github.com/gcuisinier/jenv.git ~/.jenv

To download using macOS with Homebrew, use this command:

$ brew install jenv

You can also install on Linux or macOS using Bash as follows:

$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(jenv init -)"' >> ~/.bash_profile

Alternatively, you can install on Linux or macOS using Zsh as follows:

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

After you have jEnv installed, you will need to configure it on your system as shown here. You will need to modify the script to reflect your actual path:

$ jenv add /Library/Java/JavaVirtualMachines/jdk17011.jdk/Contents/Home

You will want to repeat the jenv add command for each version of the JDK on your system. With each jenv add command, you will receive confirmation that the specific JDK version was added to jEnv as follows:

$ jenv add /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
  oracle64-1.6.0.39 added
$ jenv add /Library/Java/JavaVirtualMachines/jdk17011.jdk/Contents/Home
  oracle64-1.7.0.11 added

You can check to see what JDK versions you have added to your jEnv by using $ jenv versions at the Command Prompt. This will result in an output list.

Here are three additional jEnv commands:

  • jenv global <version>: this sets the global version
  • jenv local <version>: this sets the local version
  • jenv shell <version>: this sets the instance version for the shell