How to Use SDKMAN for Managing Java Versions
0 CommentsLast Updated on October 21, 2024 by jt
What Is SDKMAN?
As Java developers, we have to work with different versions of Java from project to project. Installing different versions by hand and setting the PATH can become a real pain at times. SDKMAN is a command line tool that allows you to install different versions of Java, Gradle, Maven and more. SDKMAN also takes care of setting environment variables for you.
Installing SDKMAN
SDKMAN can be installed on Linux and Mac based system. To install SDKMAN enter this command at the terminal:
$ curl -s "https://get.sdkman.io" | bash
After installation is complete close the terminal and open a new terminal.
Check SDKMAN Version
To check the current SDKMAN version enter this command at the terminal:
$ sdk version
This will display the current version:
SDKMAN 5.7.3+33
Update SDKMAN
To update SDKMAN enter this command at the terminal:
$ sdk update
List Available Version Of Java
To display the versions of Java, you can install enter this command at the terminal:
$ sdk list java
This will display a list of Java versions (I’m not going to list them all here)
=================================================== 11.0.2-open 11.0.1-open 10.0.2-open 10.0.1-open 9.0.4-open 8.0.201-oracle
Install Java
Let’s say you want to install Java 11.0.0-open enter this command at the terminal:
$ sdk install java 11.0.2-open
Let’s also install Java 8 using this command:
$ sdk install java 8.0.201-oracle
Display Current Java Version
To display the current version of Java in use enter this command at the terminal:
$ sdk current java
This will display this (you may have a different version):
Using java version 11.0.2-open
Switching Between Java Versions
Currently, in the example, we are using Java 11.0.2-open, and we want to switch to Java 8.0.210-oracle. To do this enter this command at the terminal:
$ skd default java 8.0.201-oracle
This will display this:
Default java version set to 8.0.201-oracle
Uninstall a Java Version
Here we will uninstall Java 8. Enter this command at the terminal:
sdk uninstall java 8.0.201-oracle
This will display this:
Uninstalling java 8.0.201-oracle
Conclusion
In the blog post, you learned how to use SDKMAN to install different versions of Java, switch between versions of Java, and uninstalling versions of Java. You can use these same methods to deal with installing tools like Maven, Gradle and so on.
Originally published at fluentjava.com