Skip to content
Latchkey

jenv: Manage Installed JDKs on PATH

jenv does not install JDKs; jenv add registers an existing JDK and jenv local/global selects which one java points to via shims.

jenv is a thin manager that switches between JDKs you already installed (via apt, brew, SDKMAN!, etc.). It is the JVM analog of rbenv and relies on the same init eval and shim model.

What it does

jenv manages multiple JDKs by adding shims to PATH. You register each JDK with jenv add <path>, then jenv local (writes .java-version) or jenv global selects the active one. The export plugin can make jenv set JAVA_HOME to match.

Common usage

bash
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
jenv add /usr/lib/jvm/temurin-21-jdk-amd64
jenv local 21                 # writes .java-version
jenv enable-plugin export     # make jenv set JAVA_HOME
java -version

Options

Command / flagWhat it does
jenv add <path>Register an installed JDK
jenv versionsList registered JDKs
jenv local <v>Pin a JDK via .java-version
jenv global <v>Set the default JDK
jenv enable-plugin exportHave jenv manage JAVA_HOME
eval "$(jenv init -)"Add jenv shims to PATH

In CI

Install the JDK first (jenv only switches, it does not download), then jenv add its path. Eval jenv init - in each step. Enable the export plugin if a build tool reads JAVA_HOME rather than java on PATH, since Gradle and Maven often do.

Common errors in CI

"jenv: version 21' is not installed" means no registered JDK matches; run jenv add for the real JDK path and check jenv versions. A Gradle/Maven build using the wrong Java means JAVA_HOME was not updated; enable the export plugin. "jenv: command not found" means init was not eval'd or ~/.jenv/bin` is off PATH.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →