jdkman is a command line tool which helps you manage multiple JDK instances.
An asciinema cast shows how to use jdkman.
This video shows how to configure jdkman on Windows.
Download the pre-built binary from the release page.
You will need to download the binary corresponding to your operating system and cpu architecture.
Rename the downloaded file jdkman-$os-$arch to jdkman
You will also need to run chmod +x jdkman on Linux or macOS.
Add the following lines in your ~/.bashrc or ~/.bash_profile or ~/.zshrc
## add jdkman to your PATH environment variable.
export PATH="$PATH:/path/to/jdkman"
eval "`jdkman init sh`"Add \path\to\jdkman to your PATH environment variable.
Then configure the profile script by entering the following lines in powershell:
echo $profile ## show the profile script location
New-Item -ItemType Directory -Path (Split-Path $profile) -Force
'Invoke-Expression -Command (jdkman init pwsh)' | Out-File -FilePath $profile -AppendSince cmd doesn't support eval nor source, there's very little that jdkman could provide.
Add \path\to\jdkman to your PATH environment variable.
Add \YourHomePath\jdkman-scripts to your PATH environment variable.
Then in cmd, run once (for each time you upgrades jdkman):
jdkman initYou can ignore the init output.
jdkman add /Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Homejdkman listAdd a file .java-version in the root directory of your project with the following content:
21
21 could be changed to any JDK versions, e.g. 11, 11.0.2, 1.8.
jdkman will find the most appropriate JDK version for you.
You could also specify the implementor (or vendor) of the JDK:
Specify the vendor name, add a colon, then specify the jdk version:
Oracle Corporation:21.0.1+12-29
java -version
echo $JAVA_HOMEFor bash|zsh|powershell, the cd command is replaced with a convenient function: cdjh
it will cd into the specified directory, and configure JAVA_HOME environment variable automatically.
You could also instead explicitly call the cdjh function.
Note: This feature is not provided for cmd, you have to set it manually by executing the following command:
for /f "delims=" %%i in ('jdkman which') do set "JAVA_HOME=%%i"- JDK 21
- GraalVM Native Image for JDK 21
To build jdkman-proxy, you will need rust|cargo.
It's already built and placed in resource folder, so you can skip rust.
./gradlew clean shadowJar
native-image \
--enable-preview \
-jar build/libs/jdkman.jar \
-Ob -march=compatibility \
--no-fallback \
-o jdkman# build `jdkman-proxy`
$arch="x86_64" # change to aarch64 if running arm windows
cd .\src\main\rust\
cargo build --release
Copy-Item .\target\release\jdkman-proxy.exe ..\resources\io\vproxy\jdkman\res\jdkman_proxy-windows-$arch.exe
cd ..\..\..\
# build jdkman
.\gradlew.bat clean shadowJar
native-image `
--enable-preview `
-jar build\libs\jdkman.jar `
--features=io.vproxy.jdkman.res.Feature `
--static `
-Ob -march=compatibility `
--no-fallback `
-o jdkmanYou can build a linux static native image using vproxyio/graalvm-jdk-21
docker run --name jdkman-build -it -v `pwd`:/workdir vproxyio/graalvm-jdk-21 /bin/bash
## inside docker
./gradlew clean shadowJar
LIBC="musl" ## or glibc
native-image \
--enable-preview \
-jar build/libs/jdkman.jar \
--static --libc=$LIBC \
-Ob -march=compatibility \
--no-fallback \
-o jdkman