DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Java
  4. SDKMAN! Managing SDKs Was Never so Easy

SDKMAN! Managing SDKs Was Never so Easy

If you’re working on multiple Java projects, it is very common to switch between different Java versions.

Monzurul Haque Shimul user avatar by
Monzurul Haque Shimul
·
Nov. 21, 18 · Tutorial
Like (7)
Save
Tweet
Share
19.65K Views

Join the DZone community and get the full member experience.

Join For Free

If you’re working on multiple Java projects, it is very common to switch between different Java versions. I face this too often. We have a number of projects running in production that need a different Java version. Sometimes, we need to fix issues or to add a customer required feature in older projects. These older projects require Java version 6 or 7, while newer projects require Java 8 or 9. So, it is often required to switch between them during development.

There are many different ways to switch between Java versions, and most of them are dependent on different OS environments i.e. MacOS, Linux, Windows, etc. Below are some examples of how to do the switching.

For Ubuntu/Debian Linux:

$ sudo update-alternatives—config java

For Redhat/Fedora:

$ su 
$ /usr/sbin/alternatives—config java 
$ /usr/sbin/alternatives—config javac

For MacOS:

$ /usr/libexec/java_home-v

When you work in multiple OS environments, i.e work in a server machine (linux distro) or on a desktop/laptop (macOS/ubuntu/windows), it is a problem to remember all these commands. So, is there any easier way to solve this problem?

Here comes SDKMAN! The Software Development Kit Manager. SDKMAN! is a tool for managing parallel versions of multiple Software Development Kits on most Unix based systems. It provides a convenient Command Line Interface (CLI) and API for installing, switching, removing and listing Candidates.

  • SDKMAN! is for making life easier for developers. No more trawling download pages, extracting archives, messing with _HOME and PATH environment variables.
  • It is written in bash and only requires curl and zip/unzip to be present on your system.
  • It runs on any UNIX based platforms: Mac OSX, Linux, Cygwin, Solaris, and FreeBSD. A Powershell CLI version is available for Windows users.
  • It allows us to manage multiple versions of each candidate.

Installation

To install this amazing tool, simply open a new terminal and enter:

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

Follow the instructions on-screen to complete the installation.

Usage

It currently supports Java, Kotlin, Scala, Groovy, Maven, Ant, Gradle, Grails, sbt, Spark, Spring Boot, VisualVM and many more. To list all the available candidates:

$ sdk list

Install the latest stable version of your SDK of choice (say, Java JDK) by running the following command:

$ sdk install java

Need a specific version of an SDK? Simply qualify the version you require:

$ sdk install java9.0.4-oracle

Listing all available candidates for Java:

$ sdk list java

================================================================================
Available Java Versions
================================================================================
     9.0.7-zulu                                                                    
   + 9.0.4-oracle                                                                  
     9.0.4-openjdk                                                                 
     8.0.172-zulu                                                                  
 > * 8.0.171-oracle                                                                
     7.0.181-zulu                                                                  
   + 7                                                                             
     10.0.1-zulu                                                                   
     10.0.1-oracle                                                                 
     10.0.0-openjdk                                                                






================================================================================
+ - local version
* - installed
> - currently in use
================================================================================

When having multiple versions installed, to see the current version in use, run:

$ sdk current java

To switch the Java version for the current terminal, run:

$ sdk use java 8.0.171-oracle

If you want to set a specific version as default for all terminals, run:

$ sdk default java 8.0.171-oracle

Now no matter what is your operating system is, you can easily switch between your SDK version running a common command.

For more detail about SDKMAN! go visit the official site.

Summary

I have shown how to manage different versions of Java using SDKMAN!. You can do similar for any supported SDKs. I must say, SDKMAN! is a must-have tool for all software developers to make life easier managing different SDK versions. Give it a try. You will love it.

Software development kit Software development Java (programming language) operating system Command-line interface

Published at DZone with permission of Monzurul Haque Shimul. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Using JSON Web Encryption (JWE)
  • Beginners’ Guide to Run a Linux Server Securely
  • How Do the Docker Client and Docker Servers Work?
  • Kubernetes vs Docker: Differences Explained

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: