In this article you will learn how to install and how to use sdkman. Sdkman (Software Development Kit Manager) is a tool to keep parallel versions of different SDKs on unix-based systems. You can easily switch between different versions without having to deal with changes in your $PATH variable. Let’s see how!
Installation
Installing SDKMAN is very easy. You can also check on their website, but it’s as simple as running this:
curl -s "https://get.sdkman.io" | bash
In order to check if the installation has been successfully completed, you can run this from the command line:
sdk version
If everything goes well, you should be seeing something similar to this:
~ sdk version
SDKMAN 5.16.0
Now that you have sdkman installed, let’s see how to use it. In our example we’ll see how to install java using sdkman.
Getting started
Installing packages – Install Java with sdkman
To install a package (also called “candidate” in sdkman) you first need to know how is the candidate named in sdkman. In some cases is very intuitive, for example to install Java, the candidate name is just java
as expected.
In this case, installing the latest java version would be as simple as the following:
sdk install java
This will install the latest default version of Java into our sdkman configuration, the output should look similar to this:
~ sdk install java
Downloading: java 17.0.5-tem
...
Done repackaging...
Cleaning up residual files...
Installing: java 17.0.5-tem
Done installing!
Now that you have installed your first package, what if you want to install a different version or even a different jdk distribution in the case of Java? What if you don’t even know the exact name of your package?
We can list candidates and their versions to get this information.
Listing packages and versions
First of all, if we don’t know the name of the package or even if we just want to check the available packages, we can run the list
command.
sdk list
When you run this command, you will get a list in the following format:
================================================================================
Available Candidates
================================================================================
q-quit /-search down
j-down ?-search up
k-up h-help
--------------------------------------------------------------------------------
Apache ActiveMQ (Classic) (5.17.1) https://activemq.apache.org/
Apache ActiveMQ® is a popular open source, multi-protocol, Java-based message
broker. It supports industry standard protocols so users get the benefits of
client choices across a broad range of languages and platforms. Connect from
clients written in JavaScript, C, C++, Python, .Net, and more. Integrate your
multi-platform applications using the ubiquitous AMQP protocol. Exchange
messages between your web applications using STOMP over websockets. Manage your
IoT devices using MQTT. Support your existing JMS infrastructure and beyond.
ActiveMQ offers the power and flexibility to support any messaging use-case.
$ sdk install activemq
--------------------------------------------------------------------------------
Ant (1.10.12) https://ant.apache.org/
Apache Ant is a Java library and command-line tool whose mission is to drive
processes described in build files as targets and extension points dependent
upon each other. The main known usage of Ant is the build of Java applications.
Ant supplies a number of built-in tasks allowing to compile, assemble, test and
run Java applications. Ant can also be used effectively to build non Java
applications, for instance C or C++ applications. More generally, Ant can be
used to pilot any type of process which can be described in terms of targets and
tasks.
$ sdk install ant
...
The packages are sorted in alphabetical order, therefore you can scroll down and find whatever package it is you’re interested in.
If you want to know the existing versions for a given package, you can also use list
but specifying what package you are interested in. For instance:
sdk list java
================================================================================
Available Java Versions for macOS ARM 64bit
================================================================================
Vendor | Use | Version | Dist | Status | Identifier
--------------------------------------------------------------------------------
Corretto | | 19 | amzn | | 19-amzn
| | 19.0.1 | amzn | | 19.0.1-amzn
| | 17.0.5 | amzn | | 17.0.5-amzn
| | 17.0.4 | amzn | | 17.0.4-amzn
| | 11.0.17 | amzn | | 11.0.17-amzn
| | 11.0.16 | amzn | | 11.0.16-amzn
| | 8.0.352 | amzn | | 8.0.352-amzn
| | 8.0.342 | amzn | | 8.0.342-amzn
Gluon | | 22.1.0.1.r17 | gln | | 22.1.0.1.r17-gln
| | 22.1.0.1.r11 | gln | | 22.1.0.1.r11-gln
GraalVM | | 22.3.r19 | grl | | 22.3.r19-grl
| | 22.3.r17 | grl | | 22.3.r17-grl
...
You will be shown a list with all the existing vendors and their corresponding versions. Once you have selected your desired package, you will have to use the name displayed in the Identifier
column.
For example, to install the latest JDK 19 Zulu version we should run:
sdk install java 19.0.1-zulu
Simple, right?
Once you have multiple versions installed, you can see what versions you have installed when you list them. For example, the Zulu packages in our host has the following:
Zulu | | 19 | zulu | | 19-zulu
| | 19.fx | zulu | | 19.fx-zulu
| | 19.0.1 | zulu | installed | 19.0.1-zulu
| | 19.0.1.fx | zulu | | 19.0.1.fx-zulu
| >>> | 17.0.5 | zulu | installed | 17.0.5-zulu
| | 17.0.5.fx | zulu | | 17.0.5.fx-zulu
| | 17.0.4.1 | zulu | | 17.0.4.1-zulu
| | 17.0.4.1.fx | zulu | | 17.0.4.1.fx-zulu
| | 11.0.17 | zulu | | 11.0.17-zulu
| | 11.0.17.fx | zulu | | 11.0.17.fx-zulu
| | 11.0.16.1 | zulu | | 11.0.16.1-zulu
| | 11.0.16.1.fx | zulu | | 11.0.16.1.fx-zulu
| | 11.0.14 | zulu | local only | 11.0.14-zulu
| | 8.0.352 | zulu | installed | 8.0.352-zulu
| | 8.0.352.fx | zulu | | 8.0.352.fx-zulu
| | 8.0.345 | zulu | | 8.0.345-zulu
| | 8.0.345.fx | zulu | | 8.0.345.fx-zulu
| | 8.0.322 | zulu | local only | 8.0.322-zulu
You will notice that the Status
column shows installed
for all those candidate versions you have installed on your machine. Also notice that the version currently in use is marked with >>>
in the Use
column (second column).
One more thing to know about list
command is that it is equivalent to ls
. You can also run sdk ls java
, for example.
How do we switch to another version then?
Switching versions
Once you’ve seen the installed versions in your machine, switching is as simple as running this.
~ sdk use java 19.0.1-zulu
Using java version 19.0.1-zulu in this shell.
If we run sdk list java
again, now the version in use should have changed.
Zulu | | 19 | zulu | | 19-zulu
| | 19.fx | zulu | | 19.fx-zulu
| >>> | 19.0.1 | zulu | installed | 19.0.1-zulu
| | 19.0.1.fx | zulu | | 19.0.1.fx-zulu
| | 17.0.5 | zulu | installed | 17.0.5-zulu
| | 17.0.5.fx | zulu | | 17.0.5.fx-zulu
As expected, the version in use now points to version 19.0.1
.
That sets the version to use in our current shell, what if we would like to set a given version as the default version to use if no other version is specified in the current session?
Setting default version
Setting a given version as the default version to use in our machine is very simple too. Let’s say we want to always use version 17.0.5-zulu
as the default Java version, what command do we need to run? The required command for this purpose is shown below:
~ sdk default java 17.0.5-zulu
Default java version set to 17.0.5-zulu
That’s quite straightforward as well, right?
That’s all you need to know about sdkman to make your life as a developer much easier!
Conclusion
In this article we’ve seen how to use sdkman to be able to switch to different versions in our machine in a very easy manner. By using sdkman we avoid having to modify our PATH variable every time that we want to use a different version of Java.
That’s all from us today! We hope you’ve found this article useful and we are looking forward to seeing you again very soon!
You must log in to post a comment.