If you’re a Java developer, you’ve probably faced the nightmare of managing multiple JDK versions on your machine. Legacy projects might require Java 8, while modern applications run on Java 17 or 21, and you may even experiment with beta releases. Manually switching between these versions—configuring environment variables and editing your system PATH—is tedious and error-prone. This is where SDKMAN! comes in, revolutionizing SDK management and making your life much easier.
What is SDKMAN!?
SDKMAN! is a powerful open-source tool designed to simplify the installation, updating, and management of technologies in the JVM ecosystem.
Still have doubts? Let’s see it in action!
Installation
Run the following command in your terminal to download and install SDKMAN!:
curl -s "https://get.sdkman.io" | bash
After installation, load the SDKMAN! initialization script:
source "$HOME/.sdkman/bin/sdkman-init.sh"
To verify the installation, run:
sdk version
You should see output similar to:
SDKMAN!
script: 5.19.0
native: 0.5.0
SDKMAN! automatically adds a startup script to your .bashrc
or .zshrc
file, ensuring the tool is available in all future terminal sessions.
Essential Commands and Practical Usage
Listing Available SDKs
To see all the SDKs and tools SDKMAN! can manage, use:
sdk list
This command displays a complete list of “candidates” (as SDKMAN! calls available SDKs), including descriptions and official websites.
Managing Java Versions
To list all available Java versions:
sdk list java
This command shows a detailed table with information about different vendors (Oracle, OpenJDK, Amazon Corretto, Azul Zulu, etc.), available versions, and installation status.
To install a specific version of Java:
sdk install java 17.0.1-open
SDKMAN! will ask if you want to set this version as default. If you answer “yes,” all new terminal sessions will use this version automatically.
Switching Between Versions
To temporarily switch to a specific version for the current session:
sdk use java 17.0.1-open
To set a version as the permanent default:
sdk default java 17.0.1-open
To check which version is currently active:
java -version
Removing Versions
To remove a version you no longer need:
sdk uninstall java 17.0.1-open
Tips and Best Practices
Checking Installed Versions
To see which Java versions are installed on your system:
sdk list java | grep installed
Upgrading SDKMAN!
To keep SDKMAN! up to date:
sdk selfupdate
Cleaning Up Old Versions
Periodically remove older versions you no longer use to save disk space:
sdk selfupdate
SDKMAN! makes managing Java environments effortless. Whether you’re working on legacy systems or the latest frameworks, this tool will save you time and headaches.
Reference:
https://sdkman.io/
Thank you for reading!