It could be challenging to deal with Java Multiverse, Gradle, Groovy, Maven, and Java (OpenJDK, Oracle JDK, Amazon Corretto, Microsoft OpenJDK, and other Java implementations). Handling versions is not a significant problem in a fantasy world where teams, tribes, squads, and whatever else operate well together and the version utilized is the most recent stable version. Yay! But, this circumstance is not real, wake up!
What is SDKMan?
SDKMan is a tool that allows you to manage multiple versions of software development kits (SDKs) on your computer. An SDK is a collection of tools that developers use to create software applications.
The SDKMan makes it simple to install, switch between, and manage SDKs for various programming languages such as Java, Kotlin, Groovy, and others. This tool allows you to install multiple versions of the same SDK and switch between them as needed, eliminating the need to worry about conflicting installations or configurations.
How to install?
It is super simple to install; simply enter the code below into your preferred terminal.
curl -s "https://get.sdkman.io" | bash
After that, add a script to your profile to load the SDK command (.bashrc, .zshrc, .bash_profile, .zprofile or .profile).
Remember to reload your terminal.
Now that the sdk command is available, you can use it to list any sdk.
To exit the interactive list, press 'q'.
Installing a SDK
sdk list java
The most recent version of Oracle is 19.0.2-oracle, so it's time to install.
sdk install java 19.0.2-oracle
So you can install Maven as well.
sdk install maven 3.9.0
Setting up a default version
The following command specifies the default version of the SDK.
sdk default java 19.0.2-oracle sdk default maven 3.9.0
Versions currently installed
This is how you can check the versions that are currently installed.
Setting up a setting for each project
You can set your SDK versions per project, first we need to create a file called .sdkmanrc.
sdk env init
Just a file sample produced by the upside command.
# Enable auto-env through the sdkman_auto_env config # Add key=value pairs of SDKs to use below java=19.0.2-oracle
The disadvantage is that we must load this environment to change the SDK version.
Uninstall an SDK version
Nothing new here!
sdk uninstall java 19.0.2-oracle
You can upgrade an only one SDK or all SDKs installed.
# only java sdk upgrade java # all sdks sdk upgrade
The following command upgrades the SDKMan tool.
If the tool does not attend to you, it is time to remove it.
rm -rf ~/.sdkman
SDKMan solves issues when dealing with multiple SDKs and versions. Now that your kernel has been updated, God bless you, my brother!