LinuxCommandLibrary

jenv

Manage multiple Java Development Kit installations

TLDR

Add a Java version to jEnv

$ jenv add [path/to/jdk_home]
copy

Display the current JDK version used
$ jenv version
copy

Display all managed JDKs
$ jenv versions
copy

Set the global JDK version
$ jenv global [java_version]
copy

Set the JDK version for the current shell session
$ jenv shell [java_version]
copy

Enable a jEnv plugin
$ jenv enable-plugin [plugin_name]
copy

SYNOPSIS

jenv [--version] [--help] <command> [<args>]

PARAMETERS

add <path>
    Add JDK at path as managed version

doctor
    Diagnose common jenv issues

enable-plugin <plugin>
    Enable a jenv plugin

global [<version>]
    Set/show global default Java version(s)

local [<version>]
    Set/show local directory Java version(s)

rehash
    Rebuild all shims (after adding versions)

remove <version>
    Remove a managed Java version

shell [<version>]
    Set/show Java version for current shell

shims
    Manage (list/install) shim executables

version
    Show current Java version(s) and flags

versions [--bare] [--short]
    List all installed Java versions (current marked with *)

which [<command>]
    Show full path to shim-resolved executable

--help
    Show general or command-specific help

--version
    Display jenv version

DESCRIPTION

jenv is a command-line tool for managing multiple Java Development Kit (JDK) versions on Unix-like systems (Linux, macOS). Inspired by rbenv and pyenv, it lets developers switch Java versions globally, per project, or per shell session without conflicts.

It works by inserting shims – lightweight executable wrappers – into your PATH. These shims dynamically resolve to the selected JDK's binaries (java, javac, jar, etc.), ensuring the correct version is used transparently. jenv tracks installed JDKs in ~/.jenv/versions and supports adding any JDK path.

Core workflows: install JDKs, add to jenv, set versions with global, local, or shell, list with versions. Plugins extend support for tools like Maven, Gradle, or export JAVA_HOME. No root access needed; fully user-managed.

Ideal for polyglot environments or legacy support (e.g., Java 8 beside 21). Requires shell initialization in .bashrc, .zshrc, etc., for PATH and shim resolution.

CAVEATS

Requires manual shell init (e.g., eval "$(jenv init -)" in ~/.zshrc). Shims limited to known Java binaries. Does not install JDKs; only manages existing ones. Temporary shell changes lost on new sessions. Not Windows-native (use WSL).

INSTALLATION

git clone https://github.com/jenv/jenv.git ~/.jenv
git clone https://github.com/jenv/jenv-openjdk.git ~/.jenv/plugins/jenv-openjdk (optional)
Add to ~/.zshrc:
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"

EXAMPLE USAGE

jenv add /opt/jdk-17
jenv global 17
jenv local 11 # per-project .java-version file created
java -version # shows JDK 17

HISTORY

Created by GutenYe in 2013 as jenv/jenv on GitHub, inspired by rbenv. Gained popularity for Java devs needing multi-version support. Maintained by community since ~2016; v0.5+ added plugins, doctor. Now at v0.5.8 (2023), with 3k+ stars.

SEE ALSO

Copied to clipboard