Follow the steps below to get a working
jenv installation with knowledge of your
java environment. Read all the code you execute carefully: a
$ symbol at the beginning of a line should be omitted, since it’s meant to show you entering a command into your terminal and observing the response after the command.
On OSX, the simpler way to install jEnv is using Homebrew
brew install jenv
Alternatively, and on Linux, you can install it from source :
git clone https://github.com/jenv/jenv.git ~/.jenv
Restart your shell by closing and reopening your terminal window or running
exec $SHELL -l in the current session for the changes to take effect.
jenv was installed, run
jenv doctor. On a macOS machine, you’ll observe the following output:
jenv is correctly loaded but Java is not yet installed.
To make sure
JAVA_HOME is set, make sure to enable the
jenv enable-plugin export
Problem? Please visit the Trouble Shooting Wiki page.
Continue to the next section to install java.
Untested: While this fork has improved
fish shell support, it has not been tested by this maintainer. To install
jenv for Fish according to the contributor’s instructions:
echo 'set PATH $HOME/.jenv/bin $PATH' >> ~/.config/fish/config.fish
jenv add to inform
jenv where your Java environment is located.
jenv does not, by itself, install Java.
For example, on macOS, use
brew to install the latest Java (OpenJDK 11) followed by the appropriate
jenv add PATH_TO_JVM_HOME command to recognize it.
brew install --cask java
With macOS OpenJDK 11.0.2 installed, for example, either of these commands will add
/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home as a valid JVM. Your JVM directory may vary!
Observe now that this version of Java is added to your
java versions command:
By default, the latest version of Java is your
system Java on macOS.
We’ll now set a
jenv local VERSION local Java version for the current working directory. This will create a
.java-version file we can check into Git for our projects, and
jenv will load it correctly when a shell is started from this directory.
jenv local 11.0.2
Yes! Observe that
JAVA_HOME is set to a valid shim directory. Unlike the main repository’s documentation we helpfully installed the
export plugin, and we now have the most important
jenv features covered.
If you executed this commands inside your
$HOME directory, you can now delete
jenv global VERSION to set a global Java version:
jenv global 11.0.2
When you next open a shell or terminal window, this version of Java will be the default.
On macOS, this sets
JAVA_HOME for GUI applications on macOS using
jenv macos-javahome. Integrates this tutorial to create a file that does not update dynamically depending on what local or shell version of Java is set, only global.
jenv shell VERSION to set the Java used in this particular shell session:
jenv shell 11.0.2
These common workflows demonstrate how to use
jenv to solve common problems.
Our goal is to have both the latest version of Java and JDK 8 installed at the same time. This is helpful for developing Android applications, whose build tools are sensitive to using an exact Java version.
We’ll resume where we left off with Java 11.0.2 installed. Let’s install Java 8 now:
brew install --cask adoptopenjdk8
This will install the latest version of Java 8 to a special directory in macOS. Let’s see which directory that is:
ls -1 /Library/Java/JavaVirtualMachines
adoptopenjdk-8.jdk directory. Your exact version may vary. We cannot retrieve this using
/usr/libexec/java_home, unfortunately. We’ll add the Java home directory using
jenv so that it shows up in our
jenv versions command:
jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/