Skip to main content
  1. Tutorials/

Manage multiple JDKs smart not hard

In this blog post, we'll discuss why it's crucial to use an SDK manager as a java developer and how to install and switch between JDKs in a few seconds.

Why should you use an SDK manager, and why is SDKMAN a crucial tool for a Java developer?
#

As a Java developer, it is common to work with different versions of Java:

  • To try out new features in the latest JDK.
  • To work on new services that run on the current LTS JDK.
  • To fix bugs in legacy services that cannot be migrated from Java 8.

Switching between different JDKs and updating the current JDK involves updating the JAVA_HOME environment variable and symlinks to the Java binaries.

To simplify this process, SDKMAN comes to the rescue. SDKMAN is a lightweight software written in Bash that requires only curl and zip/unzip to install, uninstall, update, or switch your JDKs.

Installing SDKMAN
#

curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"

To verify the installation, type: (as a result version should be printed i.e. SDKMAN 5.15.0):

sdk version

Official installation guide

Using SDKMAN
#

  1. Finding the necessary JDK To discover all available distributions of JDKs, use the following command:

    sdk list java

    The result will be a vast list of different JDK types, starting with Java 1.7 and ending with the latest releases.

    Result of sdk list java
    sdk list java — available JDK distributions
  2. Installing JDK 19 and GraalVM 22.3 with Java 19

    • Installing JDK 19

      sdk install java 19.0.1-amzn
    • Installing GraalVM 22.3 with Java 19

      sdk install java 22.3.r19-grl
Note

SDKMAN comes with an auto-complete feature that lets you fill in the Java version by pressing Tab.

Installing a JDK with SDKMAN tab-completion
  1. Switching between Java versions To switch between installed JDKs, use the default command:
sdk default java 19.0.1-amzn

This will update the symlinks and JAVA_HOME to the 19.0.1-amzn JDK

or

sdk default java 22.3.r19-grl

This will update the symlinks and JAVA_HOME to the 22.3.r19-grl JDK

Conclusion
#

If you have to work with multiple JDK, SDKMAN is a perfect tool that allows easily to manage JDKs, update existing JDK to the latest security patches, and switch quickly between various versions of java. Apart from being in change of JDKs, SDKMAN can manage different build toolss like maven, gradle,ant, etc. that can be useful for someone.

Related

About

·1 min
I'm Vladlen Gladis, a software engineer since 2016, originally from a small town in Moldova. What I work on # Java and Kotlin, the Spring ecosystem, and cloud architecture on AWS. I've built a number of distributed, reliable systems there, and untangling a complicated architecture is still my favourite kind of problem.