Java

Don’t install Java by yourself anymore, use SDKMAN! instead

For years I have been managing my JDK all by myself, for instance, you’ll find a good amount of tutorials in this blog on how to install Java or making a portable JDK for making it easier to switch versions. It works quite well but we no longer need to do any of that manually, we can use SDKMAN!.

What is SDKMAN!?

According to their official description:

SDKMAN! is a tool for managing parallel versions of multiple Software Development Kits on most Unix based systems. […]

That means that in practice you can have multiple versions of Java installed, of which you can easily switch with one command and the tool will make sure that all of your environment variables are properly exported.

Moreover, SDKMAN! isn’t limited only to Java, it supports an extensive list of SDKs including but not limited to Gradle, Groovy, Kotlin, sbt, Scala and Spark.

Why do we need it?

Working on different projects simultaneously, with the addition of the increasing adoption of microservices and the new Java release cadence, it’s common to need different versions of the language and the tools around it. So the easier it is to switch everything, the better.

How to install SDKMAN!?

The official website is well covered by tutorials, but in short, you first install the command line API:

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

and then validate it with:

sdk version

which should yield the installed version.

How to use SDKMAN!?

Typing sdk help is a good way of discovering what the tool offers.

Installing an SDK

But since we love Java, that’s how you list all the available versions of it:

sdk list java

Which will print an extensive list of JDKs from different vendors, take note of an identifier of your choice:

Shortened list of available Java versions

Let’s say we decided to install Amazon’s 11.0.4-amzn, now we do:

sdk install java 11.0.4-amzn

At the end of the installation, you will be prompted to set it as your default JDK, that’s up to you.

Java 11.0.4 from Amazon successfully installed

To verify that it worked, just check the javac version as usual:

~ javac -version
javac 11.0.4

Switching between SDK versions

You can install as many versions as you like and simply switch between them like the following:

sdk use java 8.0.212-amz

And now you have Java 8 for your older projects:

~ javac -version
javac 1.8.0_212

For more details, please visit the usage tutorials.
Happy coding =]

bgasparotto

Recent Posts

Python function decorator

This guide will show you how to create a Python function decorator with a few…

2 years ago

Got permission denied while trying to connect to the Docker daemon socket

This guide will show you how to fix the error Got permission denied while trying…

2 years ago

Python virtual environment on Intellij IDEA

This guide will show you how to create a Python virtual environment on Intellij IDEA…

2 years ago

Find and kill processes on Linux and Mac by port number

This tutorial will quickly show you how to to find and kill processes on Linux,…

2 years ago

Python: Relocation R_X86_64_PC32 against symbol can not be used when making a shared object Error

This guide shows a possible solution for Python error Relocation R_X86_64_PC32 against symbol can not…

2 years ago

Kubernetes useful commands

I condensed below a cheat sheet of Kubernetes useful commands. I will keep updating this…

2 years ago