Tame Java Version Chaos: Install and Switch JDKs with a Single SDKMAN Command
The article explains how SDKMAN, a command‑line tool for macOS, Linux and WSL, can automatically configure environment variables, manage multiple JDK versions, and switch between them with simple commands, eliminating manual downloads, PATH edits, and the need for admin rights.
What is SDKMAN?
SDKMAN! (Software Development Kit Manager) is a command‑line tool for macOS, Linux and WSL that manages JVM ecosystem SDKs such as JDKs, Maven, Gradle, Kotlin, Spring Boot CLI, Quarkus, Micronaut, etc. It configures environment variables automatically, supports side‑by‑side installations, works without administrator rights and provides a uniform command set.
Installing SDKMAN
# Run the install script
curl -s "https://get.sdkman.io" | bash
# Apply immediately (or restart terminal)
source "$HOME/.sdkman/bin/sdkman-init.sh"
# Verify installation
sdk versionA version number printed by sdk version indicates success.
Managing Java with SDKMAN
List available Java versions
sdk list javaFilter by major version
sdk list java | grep ' 8\.' # Java 8
sdk list java | grep ' 11\.' # Java 11
sdk list java | grep ' 17\.' # Java 17
sdk list java | grep ' 21\.' # Java 21
sdk list java | grep ' librca' # All Liberica buildsInstall a specific JDK
# JDK 8
sdk install java 8.0.482-librca
# JDK 11
sdk install java 11.0.30-librca
# JDK 17
sdk install java 17.0.18-librca
# JDK 21 (recommended)
sdk install java 21.0.10-librcaDuring installation SDKMAN prompts “Set X.X.X as default? (Y/n)”. Answering Y makes the installed version the global default.
Switch Java version temporarily (current terminal only)
sdk use java 21.0.10-librca
sdk use java 17.0.18-librcaThe change disappears when the terminal session ends.
Switch Java version permanently (global default)
sdk default java 21.0.10-librca
sdk default java 17.0.18-librcaAll new terminals and system reboots see the new default.
Check current Java version
sdk current java
# or
java -versionOther common Java commands
List installed JDKs: sdk list java | grep installed Find the latest patch of a major version (example for Java 21): sdk list java | grep -E '21\.[0-9]+\.[0-9]+-tem' | head -1 Uninstall a JDK: sdk uninstall java 8.0.482-librca (replace with the desired version)
Managing other SDKs
# Install Maven
sdk install maven
# Install Gradle
sdk install gradle
# Install Kotlin
sdk install kotlin
# Install Spring Boot CLI
sdk install springbootCommand pattern for any tool <tool>:
sdk list <tool> # list available versions
sdk install <tool> # install latest version
sdk use <tool> <ver> # temporary switch
sdk default <tool> <ver> # permanent switch
sdk current <tool> # show current version
sdk uninstall <tool> <ver> # uninstallProject‑specific JDK version
Place a .sdkmanrc file in the project root to lock Java (and other tool) versions. SDKMAN automatically switches when entering the directory.
# Initialize SDKMAN in the project
sdk env init
# Edit generated .sdkmanrc (example)
java=17.0.18-librca
maven=3.9.9
gradle=8.7
# Apply the configuration
sdk envLeaving the directory restores the previous default.
Maintaining SDKMAN
# List installed SDKs
sdk current
# Update SDKMAN itself
sdk selfupdate
# Clean cache
sdk flush
# Show help
sdk helpUninstall SDKMAN
# Remove SDKMAN directory
rm -rf ~/.sdkman
# Delete initialization lines from shell rc file (e.g., ~/.bashrc or ~/.zshrc)
# export SDKMAN_DIR="$HOME/.sdkman"
# source "$HOME/.sdkman/bin/sdkman-init.sh"
# Reload shell configuration
source ~/.bashrc # or source ~/.zshrcCommon issues
Running on Windows
Supported via WSL2 with identical commands.
Conflict with system‑installed Java
SDKMAN manages its own directory and takes precedence over the system PATH, avoiding conflicts.
Version switch not taking effect
Restart the terminal.
Run source "$HOME/.sdkman/bin/sdkman-init.sh".
Check for other scripts that modify JAVA_HOME.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Tech Ocean
Focused on AI programming, sharing ready-to-use development efficiency solutions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
