Managing Multiple JDK Versions with SDKMAN! – Installation, Configuration, and Usage Guide
This guide explains how to install SDKMAN!, use it to list, install, switch, and set global or project‑specific Java JDK versions, upgrade existing installations, and discover other SDKs, providing a practical solution for frequent Java version changes in microservice development.
In microservice environments Java releases a new version every six months, often requiring developers to switch JDK versions multiple times a day.
SDKMAN! is a command‑line tool that helps manage multiple JDK installations (and other SDKs) and configure a specific JDK for each codebase without repeatedly editing the JAVA_HOME environment variable.
Installing SDKMAN!
SDKMAN! can be installed on any platform using a terminal. On Windows the recommended approach is to use Windows Subsystem for Linux (WSL) and follow the official installation guide.
Installing a JDK from the SDKMAN! repository
SDKMAN! provides JDKs from several vendors such as AdoptOpenJDK, Alibaba, Amazon, etc. To view all available JDKs, run:
sdk list javaThe command prints a table of candidates. To install a chosen JDK, run:
sdk install java <candidate_version>For example:
sdk install java 15.0.1.j9-adptSDKMAN! downloads the JDK and asks whether to set it as the default version.
Setting a global JDK
Because a new JDK is released every six months, you may want to set a reasonable global (default) JDK, such as an LTS version. Use:
sdk default java <candidate_version>For example:
sdk default java 11.0.9.hs-adptThe command confirms the default JDK has been set.
Setting a local JDK for a shell session
If you want to try a new Java version without changing the global default, you can apply it only to the current shell session:
sdk use java <candidate_version>For example:
sdk use java 11.0.9.hs-adptRunning java --version then shows the active version.
Configuring JDK per project
When switching between projects frequently, create a .sdkmanrc file that defines the required JDK for the project. Generate the file with:
sdk env initThe file looks like:
# Enable automatic environment loading via sdkman_auto_env
# Add key‑value pairs for SDKs you want to use
java=11.0.9.hs-adptChange the java value to another candidate (e.g., 15.0.0.hs-adpt ) to use a different JDK for that project. Apply the settings in the folder containing the .sdkmanrc file by running:
sdk envTo have the environment applied automatically when you cd into the directory, set sdkman_auto_env=true in ~/.sdkman/etc/config .
Upgrading to a newer JDK version
The sdk upgrade command simplifies upgrading installed JDKs. For example, to upgrade JDK 11 from 11.0.8.hs-adpt to 11.0.9.hs-adpt you run:
sdk upgradeSDKMAN! lists candidates that have newer versions, prompts for confirmation, downloads, and installs the new JDK, optionally setting it as the default.
Beyond JDK management
SDKMAN! also supports many other SDKs such as Maven, Gradle, Spring Boot, Micronaut, and more. List all available SDKs with:
sdk listConclusion
SDKMAN! is a powerful tool for managing versions of Java and many other development tools, making it easy to switch, set defaults, and keep environments consistent across projects. Visit the official SDKMAN! website to explore all its features.
Cognitive Technology Team
Cognitive Technology Team regularly delivers the latest IT news, original content, programming tutorials and experience sharing, with daily perks awaiting you.
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.