SDKMAN! – The Best Tool for Managing Java Versions

Leader posted 2 min read

SDKMAN! – The Best Tool for Managing Java Versions

Introduction

If you often need to switch between Java Development Kit (JDK) versions for multiple projects, you know how time-consuming it can be. Manually installing and switching JDKs is tedious and frustrating. SDKMAN! (Software Development Kit Manager) provides a simple and efficient way to install, manage, and switch between various JDK versions effortlessly.

Without this tool, comparing different Java versions can be a real pain! All those endless changes to JAVA_HOME—ahhh!

What is SDKMAN!?

SDKMAN! is a command-line tool that allows developers to easily install and manage various software development kits (SDKs), including Java, Kotlin, Scala, and more. It works on macOS, Linux, and Windows (WSL) and supports multiple Java vendors, including OpenJDK, Oracle JDK, GraalVM, and Zulu.

How to Install SDKMAN!

Installing SDKMAN! is straightforward. Open a terminal and run:

curl -s https://get.sdkman.io | bash

After installation, restart your terminal or run:

source "$HOME/.sdkman/bin/sdkman-init.sh"

Verify the installation:

sdk version

If everything is set up correctly, you should see output similar to this:

SDKMAN!  
script: 5.19.0  
native: 0.5.0 

Using SDKMAN! for Java Management

1️⃣ Installing Java Versions

Check available JDKs:

sdk list java

For example, my output looks like this:

To install a specific JDK version, use:

sdk install java 23.0.2-graalce
 

2️⃣ Switching Between Java Versions

To temporarily switch to a different Java version, use:

sdk use java 17.0.8-tem

To set a default version for all projects:

sdk default java 23.0.2-graalce

3️⃣ Setting Project-Specific Java Versions

Inside your project directory, initialize SDKMAN!'s environment:

sdk env init

This creates a .sdkmanrc file with default content like this:

# Enable auto-env through the sdkman_auto_env config  
# Add key=value pairs of SDKs to use below  
java=23.0.2-graalce 

Edit this file to specify your required Java version. Then activate it with:

sdk env

Now, every time you enter the project directory, SDKMAN! will automatically switch to the correct JDK version!

Why Use SDKMAN!?

Simple Installation & Updates – Install and update SDKs with a single command.

Supports Multiple JDK Vendors – OpenJDK, GraalVM, Zulu, Oracle JDK, etc.

Instant Switching – No need to modify system variables manually.

Project-Specific Environments – Automatically switches JDK versions per project.

SDKMAN! vs. Other Tools

Feature SDKMAN! Homebrew + jEnv ASDF
Supports multiple JDK vendors ❌ (Only OpenJDK)
Project-specific Java versions
Works on macOS/Linux/WSL
Manages other SDKs (Scala, Kotlin, etc.)

Conclusion

SDKMAN! is an essential tool for Java developers, making JDK management effortless. Whether you're working with OpenJDK, GraalVM, or another distribution, SDKMAN! lets you install, switch, and manage Java versions easily.

This tool has personally helped me compare different Java runtime versions and saved me a ton of time when migrating multiple projects from one version to another. If you're tired of constantly tweaking JAVA_HOME, give SDKMAN! a try!

If you read this far, tweet to the author to show them you care. Tweet a Thanks

More Posts

Why Java Remains the Top Choice for Modern Server Applications

Aditya Pratap Bhuyan - Jun 28

The Secret Weapon for Java Developers Building with AI

myfear - Mar 18

Handling Large Graphs in Java with Streams: Patterns, Challenges, and Best Practices

Aditya Pratap Bhuyan - Jun 8

Data Types in Java, Part 1, the primitive types in detail

Pravin - Sep 15

Creating RESTful API Using Spring Boot for The First Time

didikts - Oct 14, 2024
chevron_left