Evergreen1 min read

Using SDKMAN on Mac

Notes on how to use SDKMAN on Mac

planted 4 November 2021
tended 5 December 2021
Using SDKMAN on Mac
Table of Contents

What is SDKMAN?copied

SDKMAN is a tool to manage multiple Software Development Kits in parallel on most Unix-based systems. It includes an easy-to-use Command Line Interface (CLI) and API for installing, switching, removing, and listing Candidates. Having used it on Mac machine to develop and maintain microservices written in different versions of Java, I am amazed by the ease of switching JDKs on the fly.

I love it so much that I wanted to replicate the same process in a Windows machine too.

Stepscopied

Since SDKMAN is built for unix systems, installation and using on a mac is smooth as butter.

  1. Install Homebrew
  2. Install SDKMAN
curl -s "https://get.sdkman.io" | bash

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

Install SDKcopied

Javacopied

  • Install my commonly used JDK versions
sdk install java 8.0.302-open

sdk install java 11.0.2-open

sdk install java 17.0.1-open

Gradlecopied

  • Install my commonly used Gradle versions
sdk install gradle 4.2.1

sdk install gradle 6.9.1

Mavencopied

  • Install maven
sdk install maven

Default Version and Auto-Switchingcopied

For example, most of my projects are written in Java 11 and only a couple of them is written in Java 8.

I would set up my environment as such:

  1. Set my default Java and Gradle versions:
sdk default java 11.0.2-open
sdk default gradle 6.9.1
  1. Navigate to the config file of your SDKMAN installation. Open the file and set sdkman_auto_env as true.
sdkman_auto_env=true
  1. Navigate to one of the projects that is using Java 8 and set up the environment using env command
# creates a .sdkmanrc config file in the base directory
sdk env init
  • In the .sdkmanrc file, I add the following:
# Enable auto-env through the sdkman_auto_env config
# Add key=value pairs of SDKs to use below
java=8.0.302-open
gradle=4.2.1
  1. Repeat for other Java 8 projects. Or you could group your projects by java versions and set the environment for multiple projects
  • Whenever I navigate to my Java 8 project, I will see the SDKs switch automatically.
$ cd my-java-8-project

Using java version 8.0.302-open in this shell.

Using gradle version 4.2.1 in this shell.

Alternatives and Other Programming Languagescopied

SDKMAN can cover most of your needs if you are solely working with Java, or related languages like Kotlin. Alternatively, you can also try jenv. For other programming languages, check out this awesome list of version managers.

Reactions

Chat with Walt-E