Jenv, A Tool for Managing Java Versions

Java Version Management Manual with jEnv

1. Overview

jEnv is a CLI tool that lets you install multiple Java versions on your system and switch between them by

global, directory (local), and shell session.

On macOS, it automatically recognizes JDKs installed at the /Library/Java/JavaVirtualMachines path.


2. Installation

(1) Install via Homebrew

brew install jenv

(2) Register Environment Variables

After installation, add the following lines to ~/.zshrc (or ~/.bash_profile).

export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"

Apply:

source ~/.zshrc

3. Checking and Registering Java Versions

(1) Check Installed JDK List on the System

/usr/libexec/java_home -V

Example output:

Matching Java Virtual Machines (3):
    17.0.8 (arm64) "Oracle Corporation" - "Java SE 17"
        /Library/Java/JavaVirtualMachines/jdk-17.0.8.jdk/Contents/Home
    11.0.21 (arm64) "Adoptium" - "OpenJDK 11"
        /Library/Java/JavaVirtualMachines/jdk-11.0.21.jdk/Contents/Home

(2) Register a Version with jEnv

jenv add /Library/Java/JavaVirtualMachines/jdk-17.0.8.jdk/Contents/Home
jenv add /Library/Java/JavaVirtualMachines/jdk-11.0.21.jdk/Contents/Home

Check the registered list:

jenv versions

Example output:

* system (set by /Users/chris/.jenv/version)
  17.0.8
  11.0.21

4. Switching Versions

(1) Global Switch

The version applied by default across all terminals:

jenv global 17.0.8

Verify:

java -version

(2) Local (Directory) Switch

The version applied only within a specific project directory:

cd ~/workspace/myapp
jenv local 11.0.21

A .java-version file will be created in that directory:

11.0.21

(3) Session Switch

Temporarily switch only for the current terminal session:

jenv shell 17.0.8

5. Enabling Plugins

Some build tools (Maven, Gradle, etc.) may not recognize the JAVA_HOME set by jEnv.

In that case, you need to activate the plugin with the command below.

jenv enable-plugin export

After activation, restart the terminal or run:

exec $SHELL -l

jEnv will now automatically manage the JAVA_HOME environment variable.


6. Checking Environment Variables

echo $JAVA_HOME

Expected output:

/Users/chris/.jenv/versions/17.0.8

7. jEnv Command Summary

CommandDescription
jenv add <경로>Register a new JDK with jEnv
jenv versionsCheck the list of registered versions
jenv global <버전>Set the global default version
jenv local <버전>Set a version for the current directory only
jenv shell <버전>Set a version for the current terminal session only
jenv enable-plugin exportEnable automatic JAVA_HOME management
jenv which javaCheck the currently active Java path
jenv doctorInspect for configuration issues

8. Per-Project Management Example

Assume you have the following project structure:

~/projects/
├── backend-java11/
│   └── .java-version → 11.0.21
└── backend-java17/
    └── .java-version → 17.0.8

In this case, entering cd backend-java11 will automatically switch to Java 11,

and entering cd backend-java17 will automatically switch to Java 17.


9. Troubleshooting

IssueCauseSolution
java -version shows system version instead of jEnv versionexport plugin not activatedRun jenv enable-plugin export and restart the shell
.java-version is not being appliedMust enter the directory firstRefresh with cd . command or exec $SHELL -l
jenv: no such commandPATH or initialization is missingAdd eval "$(jenv init -)" to .zshrc
jEnv version not reflected in IDEIDE not referencing JAVA_HOMESpecify the JDK path directly in IDE settings

  1. Install multiple JDKs via Homebrew

    brew install openjdk@17
    brew install openjdk@11
  2. Confirm paths with /usr/libexec/java_home -V

  3. Register each version with jEnv

  4. Activate jenv enable-plugin export

  5. Create a .java-version file per project

With this setup,

you can reliably manage projects that require different JDK versions per build environment.


11. Appendix: JDK Installation Path Examples (macOS)

VersionPath
OpenJDK 17/Library/Java/JavaVirtualMachines/openjdk-17.jdk/Contents/Home
Temurin 11/Library/Java/JavaVirtualMachines/temurin-11.jdk/Contents/Home
Zulu 8/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home