I always install Node.js through
nvm and Python through
pyenv. Node.js keeps project dependencies inside the project folders itself and doesn’t clutter the system. Similarly, for Python, there is
venv which helps me keep dependencies isolated. But I was not using any such thing for Java development. I always had the latest LTS release of JDK installed globally and used it for everything. This used to work always because Java versions didn’t have to be changed as often as Node.js or Python (between Python 2 and 3). In fact, Java version didn’t have to be changed at all.
But now I have a need to switch between Java 8 and Java 11 as part of my work. And also, I’d like to keep up with new features in new releases of Java. Also, I need to test my software with a couple of JVMs ever since Oracle messed with their support terms for Java sometime in the last year. So in summary, I need to now frequently switch versions / distributions of JDK on my computer. Yeah, there is the
alternatives thing for Linux, but I found a neater, open-source solution on the internet. SDKMAN!
SDKMAN! is a pyenv alternative or nvm alternative for Java. Read their install and usage documentation for detailed instructions and their full feature set. Some commands –
sdk install javato install the latest stable OpenJDK
sdk list javato list all available Java installations (with info on what’s already installed)
sdk install java 220.127.116.11.1-amznto install Amazon Corretto JDK version 16
sdk use java 11.0.11.hs-adptto switch to OpenJDK 11 for the current shell
sdk default java 18.104.22.168.1-amznto switch to Amazon Corretto JDK as the default
There is many more features, support for other tools like Ant, Spring Boot and so on. There’s even a
.sdkmanrc file that can be added in my project so everyone in my team can stay on the same version. This is a neat little tool that I wish I had found earlier.