SDKMAN! meets Windows

15.09.2023

SDKMAN! is a neat tool for managing various software development kits on Unix-based systems. Recently I wondered if I could take advantage of SDKMAN! on Windows as well. I tested it and was happy to find that the answer is yes! I even got it  to work with a new unreleased Java version (or at least the switching part).

SDKMAN! on Windows

One option is to use SDKMAN! in WSL. Since this is a real Linux running in a VM, you can use SDKMAN! out of the box.

But what about projects that are located directly under Windows, and not in WSL? Can you use SDKMAN! for them as well? Again, the answer is yes. With a little additional setup effort, SDKMAN! works also directly under Windows.

As a precondition, git bash (you can get it here) and 7-Zip need to be installed.

Setting it up

(Note: all commands must be executed within the git bash.)

The first thing I tried was to run the installation command from the SDKMAN! docs:

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

Beneath a great ASCII art there was a message stating that the zip tool was needed, which is not present in git bash by default.

So I created a copy of the 7z.exe in /usr/bin of git bash (renamed to zip.exe) by running the following command:

$ cp /c/Program\ Files/7-Zip/7z.exe /usr/bin/zip.exe

Now the installation command worked, and SDKMAN! could be installed successfully.

(Note: from here on, everythin works exactly the same as in Unix-based systems. The only Windows-specific todo was providing the zip tool in the git bash.)

Installing Java SDKs

Having SDKMAN! ready, I went on using it to install some Java SDKs. First the latest version of Java 17 Temurin:

$ sdk install java 17.0.8.1-tem

Even bash completion worked, which was helpful to find the correct name of the required version and distribution.

SDKMAN! asked if this version should be the default (active when a new shell is opened), to which I agreed.

When the installation was finished I checked the Java version:

$ java -version
openjdk version „17.0.8.1“ 2023-08-24
OpenJDK Runtime Environment Temurin-17.0.8.1+1 (build 17.0.8.1+1)
OpenJDK 64-Bit Server VM Temurin-17.0.8.1+1 (build 17.0.8.1+1, mixed mode, sharing)

$ echo $JAVA_HOME
/c/Users/devmachine/.sdkman/candidates/java/17.0.8.1-tem

Time to install another SDK (Java 11 Temurin):

$  sdk install java 11.0.20.1-tem

To switch to this version, I executed the following command:

$  sdk use java 11.0.20.1-tem

The bash completion worked here, too, offering only the already installed Java SDKs. So I just had to type up to the „11“, the rest of the SDK name being completed automatically after pressing TAB.

Checking if Java 11 is now active:

$ java -version
openjdk version „11.0.20.1“ 2023-08-24
OpenJDK Runtime Environment Temurin-11.0.20.1+1 (build 11.0.20.1+1)
OpenJDK 64-Bit Server VM Temurin-11.0.20.1+1 (build 11.0.20.1+1, mixed mode)

$ echo $JAVA_HOME
/c/Users/devmachine/.sdkman/candidates/java/11.0.20.1-tem

Using SDKMAN! with Java release candidates

It is not possible with SDKMAN! to install Java versions that are not yet officially released. However you can use SDKMAN! anyway to switch to such versions after having installed them manually.

Since the official release of Java 21 was only a few days away from the publishing date of this blog post, I wanted to have a look at its features.

Therefore I downloaded the release candidate for Windows/x64 from the OpenJDK site for Java 21, saved it under C:\Users\devmachine\.sdkman\candidates\java\ and unzipped it:

$ unzip openjdk-21_windows-x64_bin.zip

To get a name that better suits the SDKMAN! naming conventions, I renamed the resulting folder:

$ mv jdk-21 21.rc-openjdk

Now when running the command sdk list java, I found the following entry at the bottom of the list:

================================================================================
 Vendor        | Use | Version      | Dist    | Status     | Identifier

… (list of all other available versions)

Unclassified   |     | 21.rc        | none    | local only | 21.rc-openjdk
================================================================================

Using the known command, I was now able to switch to the OpenJDK 21 RC version:

$ sdk use java 21.rc-openjdk

Again, I could use bash completion to select the desired version, typing only up to the „21“ and pressing TAB. Checking the result:

$ java -version
openjdk version „21“ 2023-09-19
OpenJDK Runtime Environment (build 21+35-2513)
OpenJDK 64-Bit Server VM (build 21+35-2513, mixed mode, sharing)

$ echo $JAVA_HOME
/c/Users/devmachine/.sdkman/candidates/java/21-rc-openjdk

Conclusion

SDKMAN! is a great tool I never want to miss anymore. And the good news is that it works for Windows, too, and it even can be used to switch to unreleased Java Versions (except the installation part).

Zurück zur Übersicht

Kommentar verfassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

*Pflichtfelder

*