Operations 7 min read

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.

Tech Ocean
Tech Ocean
Tech Ocean
Tame Java Version Chaos: Install and Switch JDKs with a Single SDKMAN Command

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 version

A version number printed by sdk version indicates success.

Managing Java with SDKMAN

List available Java versions

sdk list java

Filter 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 builds

Install 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-librca

During 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-librca

The 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-librca

All new terminals and system reboots see the new default.

Check current Java version

sdk current java
# or
java -version

Other 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 springboot

Command 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> # uninstall

Project‑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 env

Leaving 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 help

Uninstall 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 ~/.zshrc

Common 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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaLinuxJDKcommand-lineVersion ManagementSDKMAN
Tech Ocean
Written by

Tech Ocean

Focused on AI programming, sharing ready-to-use development efficiency solutions.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.