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
| Command | Description |
|---|---|
jenv add <경로> | Register a new JDK with jEnv |
jenv versions | Check 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 export | Enable automatic JAVA_HOME management |
jenv which java | Check the currently active Java path |
jenv doctor | Inspect 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
| Issue | Cause | Solution |
|---|---|---|
java -version shows system version instead of jEnv version | export plugin not activated | Run jenv enable-plugin export and restart the shell |
.java-version is not being applied | Must enter the directory first | Refresh with cd . command or exec $SHELL -l |
jenv: no such command | PATH or initialization is missing | Add eval "$(jenv init -)" to .zshrc |
| jEnv version not reflected in IDE | IDE not referencing JAVA_HOME | Specify the JDK path directly in IDE settings |
10. Recommended Workflow
-
Install multiple JDKs via Homebrew
brew install openjdk@17 brew install openjdk@11 -
Confirm paths with
/usr/libexec/java_home -V -
Register each version with jEnv
-
Activate
jenv enable-plugin export -
Create a
.java-versionfile 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)
| Version | Path |
|---|---|
| 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 |