Easily Manage Different Java Versions on Your Machine with SDKMan!

Uncategorized

So, you’re a Java developer, or maybe you’re aspiring to be one. Either way, you’ve probably faced the challenge of managing multiple versions of Java on your machine. One project requires Java 8, but another needs Java 11, yet another requires Java 17. The open-source library you’re keen on contributing to needs yet another version. What do you do? You start juggling environment variables, and before you know it, your system is a tangled mess of configurations. Not fun, right?

And let’s not even get started on the difference between JRE and JDK. It’s easy for beginners to get confused about the distinction between the two. The JRE (Java Runtime Environment) is sufficient if you just want to run Java applications, but if you’re going to be developing them, you’ll need the JDK (Java Development Kit). The JDK includes everything the JRE has, plus additional tools and utilities for developers like the Java compiler, or javac.

Tired of all this complexity? Let me introduce you to SDKMan!, a version manager that streamlines the process, making it a breeze to manage multiple Java versions on your machine. Not just Java, SDKMan! can be used to manage a lot more kits and tools such as Maven. In this blog post however, we see how to use SDKMan! to effortlessly manage different versions of Java on the same machine. 

What is SDKMan?

SDKMan!stands for Software Development Kit Manager, a shell script that allows you to manage parallel versions of multiple Software Development Kits for JVM-based languages like Java, Groovy, and Kotlin. With a simple command, you can switch between different versions, set a default version, and do much more.

Installing SDKMan!

To get started, you’ll first need to install SDKMan! on your system, with the following command:

curl -s "https://get.sdkman.io" | bash

After the installation is complete, open a new terminal window and type the following to ensure that SDKMan! has been installed:

sdk version

You should see the SDKMan! version displayed, confirming that the installation was successful.

Managing Java Versions

To see all the versions available for installation, including those you have already installed on your machine, you can run:

sdk list java

To install a specific version, you can use:

sdk install java [version]

For example, to install the latest upcoming Java 21 from OpenJDK, you can run:

sdk install java 21.ea.35-open

Switching between different versions is as simple as running:

sdk use java [version]

To set a particular version as your default:

sdk default java [version]

So for instance, to set the aforementioned Java 21 as the default JDK on your machine, you can run

sdk default java 21.ea.35-open

You can do all this without messing around with environment variables or system settings. It’s that simple.

You can also see the list of all available tools, SDKs and libraries you can install with SDKMan! with the command:

sdk list  

Wrapping Up

Managing multiple Java versions doesn’t have to be a headache. SDKMan! has you covered, offering a straightforward way to handle different versions without the hassle of juggling configurations manually. With just a few commands, you can install, switch between, or even uninstall different versions of Java (JDK or JRE, it doesn’t matter!).

So, the next time you find yourself wrestling with Java versions, just remember: SDKMan! is here to make your life a whole lot easier.

Happy coding!

Fully managed Jakarta EE Cloud Deployment. ✅Handles Kubernetes for you.✅ 15 day free trial available.✅

Payara Cloud.

TRY FREE.

Comments (0)

Post a comment

Your email address will not be published. Required fields are marked *

Payara needs the contact information you provide to us to contact you about our products and services. You may unsubscribe from these communications at any time. For information on how to unsubscribe, as well as our privacy practices and commitment to protecting your privacy, please review our Legal & Privacy Policy.

Related Posts

How to Run and Scale AI Java Applications in Production: An Overview for Developers with no Machine Learning Expertise 9 minutes
Jakarta EE

How to Run and Scale AI Java Applications in Production: An Overview for Developers with no Machine Learning Expertise

Organizations are increasingly interested in adopting artificial intelligence (AI) and generative AI (GenAI) to improve operations and offer next-generation […]

Payara Qube-Cloud Light banner 4 minutes
Security

Zero Trust Security in Enterprise Java: What it is and How to Implement it

Cybersecurity isn’t just about building walls, fortresses, moats or any other external barrier anymore. Nowadays, it’s important to check […]

Community_Announcement 4 minutes
Uncategorized

Leading the Way: Payara Platform Community 7 Beta Now Fully Jakarta EE 11 Certified

We’re excited to announce that Payara Platform Community 7 Beta application server is now fully certified as Jakarta EE 11 […]