Installing OpenJDK with SDKMAN in Linux

Taehyeong LeeTaehyeong Lee
2 min read

Installing SDKMAN

  • Installing SDKMAN allows for easy installation and version switching of OpenJDK.
# Install SDKMAN in Linux, macOS
$ curl -s "https://get.sdkman.io" | bash
$ source "$HOME/.sdkman/bin/sdkman-init.sh"

Installing OpenJDK 21

  • This is an example of installing OpenJDK 21, the most current LTS version.
# Install Amazon Corretto 21 and set as the default JDK
$ sdk i java 21.0.2-amzn
$ sdk default java 21.0.2-amzn

# Check installed version
$ java --version
openjdk 21.0.2 2024-01-16 LTS

Switching between OpenJDK 17 and 21

  • In a local development environment, there may be a need to switch between different versions of OpenJDK for different projects. This can be easily done by executing the sdk default java {identifier} command.
# Install Amazon Corretto 17
$ sdk i java 17.0.10-amzn

# Switch to OpenJDK 17
$ sdk default java 17.0.10-amzn
$ java --version
openjdk 17.0.10 2024-01-16 LTS

# Switch back to OpenJDK 21
$ sdk default java 21.0.2-amzn
$ java --version
openjdk 21.0.2 2024-01-16 LTS

# Create Aliases for quick and convenient transitions
$ nano ~/.bash_aliases
alias java17="sdk default java 17.0.10-amzn; java --version"
alias java21="sdk default java 21.0.2-amzn; java --version"

Installing Kscript

  • Additionally, installing kscript allows for the creation of shell scripts using Kotlin.
# Install kscript
$ sdk install kotlin
$ sdk install kscript
$ sdk install springboot
0
Subscribe to my newsletter

Read articles from Taehyeong Lee directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Taehyeong Lee
Taehyeong Lee