| Crates.io | jvr |
| lib.rs | jvr |
| version | 0.3.2 |
| created_at | 2024-06-29 08:27:53.051862+00 |
| updated_at | 2026-01-05 16:40:40.559887+00 |
| description | A simple and easy-to-use Java version manager (registry: jvr), similar to Node.js's nvm, but it does not follow nvm's naming convention. Otherwise, it would be named 'jvm', which could cause command conflicts or ambiguity. |
| homepage | https://github.com/photowey/jvr |
| repository | https://github.com/photowey/jvr |
| max_upload_size | |
| id | 1287217 |
| size | 103,166 |
jvrA simple and easy-to-use Java version manager (registry: jvr), similar to Node.js's nvm,
but it does not follow nvm's naming convention. Otherwise, it would be named jvm,
which could cause command conflicts or ambiguity.
v0.3.2More robust and permission-friendly directory linking on Windows:
JDK directory (e.g., jdk11) to a init($ jvr init /path/to/java_home) location (e.g., /path/to/xxx) works reliably for all standard users on Windowssymlinks, or regular directories—are correctly and safely removed before recreationPlatform Supportjvr supports the following operating systems:
Windows (Windows 10/11)Linux (various distributions)macOS (various versions)InstallDownload executable Download the executable file directly from GitHub and put it in any $PATH path.
Cargo# 1.github
$ cargo install --git https://github.com/photowey/jvr.git [--branch main]
# 2.crates.io
$ cargo install jvr
Build from sourcegit clone https://github.com/photowey/jvr.git
cd jvr
cargo build --release
UsageQuick StartFirst-time setup (required):
# Step 1: Initialize jvr with a JAVA_HOME path
$ jvr init /path/to/java_home
# Step 2: Add JDK versions
$ jvr add jdk8 /path/to/jdk8
$ jvr add jdk11 /path/to/jdk11
# Step 3: Switch between JDK versions
$ jvr use jdk11
Complete Workflow Diagram:
sequenceDiagram
participant User
participant jvr
participant Filesystem
participant EnvVars
Note over User,EnvVars: Step 1: Initialize (One-time)
User->>jvr: jvr init ~/.jvr/java_home
jvr->>Filesystem: Create JAVA_HOME directory
jvr->>EnvVars: Set JAVA_HOME environment variable
jvr->>EnvVars: Add JAVA_HOME/bin to PATH
jvr->>Filesystem: Save JAVA_HOME path to config.json
jvr->>User: Initialized
Note over User,EnvVars: Step 2: Add JDK Versions
User->>jvr: jvr add jdk8 /path/to/jdk8
jvr->>Filesystem: Verify JDK path exists
jvr->>Filesystem: Save JDK info to config.json
jvr->>User: Added
User->>jvr: jvr add jdk11 /path/to/jdk11
jvr->>Filesystem: Verify JDK path exists
jvr->>Filesystem: Save JDK info to config.json
jvr->>User: Added
Note over User,EnvVars: Step 3: Switch JDK (Fast)
User->>jvr: jvr use jdk11
jvr->>Filesystem: Remove old symlink (if exists)
jvr->>Filesystem: Create symlink JAVA_HOME to /path/to/jdk11
jvr->>Filesystem: Update current JDK in config.json
jvr->>User: Switched
Note over User,EnvVars: Subsequent switches are instant
User->>jvr: jvr use jdk8
jvr->>Filesystem: Update symlink JAVA_HOME to /path/to/jdk8
jvr->>User: Switched (No env var update needed)
CommandsInit (v0.3.0+)Initialize jvr with a JAVA_HOME path. This command must be run once before using other commands.
What it does:
JAVA_HOME/bin to your PATH environment variable$ jvr init -h | --help
$ jvr init <JAVA_HOME_PATH>
# e.g.:
$ jvr init ~/.jvr/java_home
$ jvr init "C:\Users\YourName\.jvr\java_home"
Note: After running jvr init, you may need to reload your shell configuration (Unix) or restart your terminal (Windows) for the environment variables to take effect.
Command Flow:
flowchart TD
START(["jvr init path"]) --> CHECK{"Path exists?"}
CHECK -->|No| CREATE["Create directory"]
CHECK -->|Yes| SET_ENV["Set JAVA_HOME env var"]
CREATE --> SET_ENV
SET_ENV --> CHECK_PATH{"JAVA_HOME/bin in PATH?"}
CHECK_PATH -->|No| ADD_PATH["Add JAVA_HOME/bin to PATH"]
CHECK_PATH -->|Yes| SAVE_CONFIG["Save JAVA_HOME path to config.json"]
ADD_PATH --> SAVE_CONFIG
SAVE_CONFIG --> SUCCESS(["Initialized"])
style START fill:#e3f2fd
style SUCCESS fill:#c8e6c9
style CREATE fill:#fff9c4
style SET_ENV fill:#fff9c4
style ADD_PATH fill:#fff9c4
AddRegister a JDK version with an alias name.
$ jvr add -h | --help
$ jvr add <NAME> <PATH>
# e.g.:
$ jvr add jdk8 /usr/lib/jvm/java-8-openjdk
$ jvr add jdk11 /usr/lib/jvm/java-11-openjdk
$ jvr add jdk17 "C:\Program Files\Java\jdk-17"
Note: This command only registers the JDK path. It does not modify environment variables.
Command Flow:
flowchart TD
START(["jvr add name path"]) --> CHECK_EXISTS{"JDK already registered?"}
CHECK_EXISTS -->|Yes| EXISTS_MSG["Print: Already added"]
CHECK_EXISTS -->|No| CHECK_PATH{"Path exists?"}
CHECK_PATH -->|No| ERROR["Error: Path not found"]
CHECK_PATH -->|Yes| ADD["Add to versions list"]
ADD --> SAVE["Save to config.json"]
SAVE --> LIST["Display JDK list"]
EXISTS_MSG --> LIST
LIST --> END(["Complete"])
ERROR --> END
style START fill:#e3f2fd
style END fill:#c8e6c9
style ERROR fill:#ffcdd2
style ADD fill:#fff9c4
style SAVE fill:#fff9c4
ListList all registered JDK versions in a formatted table. The * indicates the version currently in use.
$ jvr list
UseSwitch to a specific JDK version by creating a symlink from JAVA_HOME to the selected JDK path.
$ jvr use <NAME>
# e.g.:
$ jvr use jdk11
How it works (v0.3.0+):
init) to the selected JDK pathinitNote: You must run jvr init before using this command.
Command Flow:
flowchart TD
START(["jvr use name"]) --> CHECK_INIT{"Initialized?"}
CHECK_INIT -->|No| INIT_ERROR["Error: Run jvr init first"]
CHECK_INIT -->|Yes| FIND_JDK{"Find JDK by name"}
FIND_JDK -->|Not found| NOT_FOUND["Error: JDK not found"]
FIND_JDK -->|Found| CHECK_PATH{"JDK path exists?"}
CHECK_PATH -->|No| PATH_ERROR["Error: Path not found"]
CHECK_PATH -->|Yes| REMOVE_OLD{"Old symlink exists?"}
REMOVE_OLD -->|Yes| DELETE["Remove old symlink"]
REMOVE_OLD -->|No| CREATE_SYMLINK["Create symlink JAVA_HOME to JDK"]
DELETE --> CREATE_SYMLINK
CREATE_SYMLINK --> UPDATE_CURRENT["Update current JDK in config"]
UPDATE_CURRENT --> SAVE["Save config.json"]
SAVE --> LIST["Display JDK list"]
LIST --> SUCCESS(["Switched"])
INIT_ERROR --> END(["Exit"])
NOT_FOUND --> END
PATH_ERROR --> END
style START fill:#e3f2fd
style SUCCESS fill:#c8e6c9
style INIT_ERROR fill:#ffcdd2
style NOT_FOUND fill:#ffcdd2
style PATH_ERROR fill:#ffcdd2
style CREATE_SYMLINK fill:#fff9c4
style UPDATE_CURRENT fill:#fff9c4
VersionView the version of jvr itself.
$ jvr version
OpenOpen the directory where jvr configuration is located.
$ jvr open
How It Works (v0.3.0)Symlink-Based Architecturejvr v0.3.0 uses a symlink-based approach for faster JDK switching:
jvr init): Sets up a fixed JAVA_HOME path and configures environment variables oncejvr add): Registers JDK paths without modifying environment variablesjvr use): Creates/updates a symlink from JAVA_HOME to the selected JDKBenefits:
initArchitecture Diagramgraph TB
subgraph UserEnv["User Environment"]
JAVA_HOME["JAVA_HOME<br/>(Fixed Path)"]
PATH["PATH<br/>(Includes JAVA_HOME/bin)"]
end
subgraph JvrMgmt["jvr Management"]
SYMLINK["Symlink<br/>(JAVA_HOME to JDK)"]
CONFIG["config.json<br/>(JDK Registry)"]
end
subgraph JDKInst["JDK Installations"]
JDK8["JDK 8<br/>/path/to/jdk8"]
JDK11["JDK 11<br/>/path/to/jdk11"]
JDK17["JDK 17<br/>/path/to/jdk17"]
end
JAVA_HOME -->|Points to| SYMLINK
SYMLINK -->|Links to| JDK11
CONFIG -->|Stores| JDK8
CONFIG -->|Stores| JDK11
CONFIG -->|Stores| JDK17
style JAVA_HOME fill:#e1f5ff
style SYMLINK fill:#fff4e1
style CONFIG fill:#e8f5e9
style JDK11 fill:#ffebee
Configuration File Locationjvr stores its configuration in:
%USERPROFILE%\.jvr\config.json~/.jvr/config.jsonThe configuration file stores:
init)Environment Variablesjvr manages the following environment variables:
jvr init (configured once)$JAVA_HOME/bin (Unix) or %JAVA_HOME%\bin (Windows)Important: After running jvr init, you need to:
source ~/.bashrc or source ~/.zshrc)Shell Configuration Files (Unix)On Unix systems (Linux/macOS), jvr automatically detects your shell and writes environment variables to the appropriate configuration file:
~/.zshrc, ~/.zshenv~/.bashrc, ~/.bash_profile, ~/.profile~/.profileThe tool will use the first available file in the list above.
ExamplesComplete Workflow# Step 1: Initialize jvr (one-time setup)
$ jvr init ~/.jvr/java_home
✅ Created JAVA_HOME directory: /home/user/.jvr/java_home
✅ jvr initialized successfully!
JAVA_HOME: /home/user/.jvr/java_home
Use 'jvr use <alias>' to switch between JDK versions.
# Reload shell configuration (Unix only)
$ source ~/.bashrc # or ~/.zshrc
# Step 2: Add JDK versions
$ jvr add jdk8 /usr/lib/jvm/java-8-openjdk
✅ Added JDK version: ['jdk8']
$ jvr add jdk11 /usr/lib/jvm/java-11-openjdk
✅ Added JDK version: ['jdk11']
$ jvr add jdk17 /usr/lib/jvm/java-17-openjdk
✅ Added JDK version: ['jdk17']
# Step 3: List all registered JDKs
$ jvr list
+-----+-------+----------------------------------+---------+
| # | Alias | Path | Current |
+=====+=======+==================================+=========+
| 1 | jdk8 | /usr/lib/jvm/java-8-openjdk | - |
| 2 | jdk11 | /usr/lib/jvm/java-11-openjdk | - |
| 3 | jdk17 | /usr/lib/jvm/java-17-openjdk | - |
+-----+-------+----------------------------------+---------+
# Step 4: Switch to a specific JDK version
$ jvr use jdk17
✅ Now using JDK jdk17 at /usr/lib/jvm/java-17-openjdk
JAVA_HOME symlink: /home/user/.jvr/java_home -> /usr/lib/jvm/java-17-openjdk
# Verify the change
$ echo $JAVA_HOME
/home/user/.jvr/java_home
$ java -version
openjdk version "17.0.x" ...
# Switch to another JDK (fast, no environment variable update needed)
$ jvr use jdk11
✅ Now using JDK jdk11 at /usr/lib/jvm/java-11-openjdk
JAVA_HOME symlink: /home/user/.jvr/java_home -> /usr/lib/jvm/java-11-openjdk
Platform-Specific ExamplesWindows:
# Initialize
$ jvr init "C:\Users\YourName\.jvr\java_home"
✅ Created JAVA_HOME directory: C:\Users\YourName\.jvr\java_home
✅ jvr initialized successfully!
# Add and use JDKs
$ jvr add jdk21 "C:\Program Files\Java\jdk-21"
$ jvr use jdk21
✅ Now using JDK jdk21 at C:\Program Files\Java\jdk-21
JAVA_HOME symlink: C:\Users\YourName\.jvr\java_home -> C:\Program Files\Java\jdk-21
Linux/macOS:
# Initialize
$ jvr init ~/.jvr/java_home
✅ Created JAVA_HOME directory: /home/user/.jvr/java_home
✅ jvr initialized successfully!
# Reload shell
$ source ~/.bashrc # or ~/.zshrc
# Add and use JDKs
$ jvr add jdk21 /usr/lib/jvm/java-21-openjdk
$ jvr use jdk21
✅ Now using JDK jdk21 at /usr/lib/jvm/java-21-openjdk
JAVA_HOME symlink: /home/user/.jvr/java_home -> /usr/lib/jvm/java-21-openjdk
Troubleshooting"jvr has not been initialized" ErrorIf you see this error when running jvr use:
❌ jvr has not been initialized. Please run 'jvr init <JAVA_HOME_PATH>' first.
Solution: Run jvr init with a JAVA_HOME path before using other commands:
$ jvr init ~/.jvr/java_home
Environment Variable Not Updated After Init (Unix)If JAVA_HOME is not set after running jvr init:
Check if the environment variable was written to your shell config file:
$ cat ~/.bashrc | grep JAVA_HOME
# or
$ cat ~/.zshrc | grep JAVA_HOME
Reload your shell configuration:
$ source ~/.bashrc # or ~/.zshrc
Verify in a new terminal window:
$ echo $JAVA_HOME
Symlink Creation FailedIf you encounter errors when switching JDK versions:
Windows:
Unix:
Permission Denied (Unix)If you encounter permission errors:
# Check permissions
$ ls -la ~/.jvr/
# Fix permissions if needed
$ chmod 755 ~/.jvr/java_home
Note: It's recommended to use user-level directories (like ~/.jvr/java_home) to avoid permission issues.
JDK Path Does Not ExistIf you see this error when adding or using a JDK:
❌ JDK path does not exist: /path/to/jdk
Solution: Verify the JDK path is correct and the directory exists:
$ ls -la /path/to/jdk
# or on Windows
$ dir "C:\path\to\jdk"
LicenseLicensed under the Apache License, Version 2.0. See LICENSE for details.