Flexible switching and management of multiple java versions
Foreword: In the past two years, the Java version has been upgraded frequently, and I feel that I have just mastered Java8. When writing this article, I have heard the news of java14, whether it is to try new features (the use of the super powerful function of Collectors.teeing in Java12) or due to project For upgrade/compatibility needs, we may all face the situation of managing multiple Java versions.

In addition, Oracle has changed the user agreement since Java11, and any commercial use will be charged. While writing this article, I got the news "Microsoft announced that it will join OpenJDK". If you can't beat it, choose OpenJDK. Just G for a while, just understand it as a story
(Recommended video: java video tutorial)
Configuring a single Java environment variable itself has no technical content at all, but when multiple Java versions need to be managed, repeatedly configuring environment variables is obviously very boring. According to the traditional configuration method, we cannot flexibly switch Java versions
How to easily manage and use multiple versions of Java?
Multi-version Java management
Obviously we are not the first to have this dilemma. There are three existing solutions that I know of:
● Jabba
● jenv
● sdkman
This article mainly explains how to break the difficulties we face through sdkman and help us flexibly configure Introduction to using Java
sdkman
SDKMAN is a software development toolkit for managing multiple software (Java, Groovy, Scala, Kotlin and Ceylon. Ant, Gradle, etc.).
It provides a convenient command line interface (CLI) and API for installing, switching, removing and listing candidates. This article mainly explains the use of sdkman by managing Java
sdkman installation
It is very easy to install sdkman on a Unix-like platform. It can be successfully installed on Mac OSX, Linux, WLS, Cygwin, Solaris and FreeBSD, and also supports Bash and ZSH shells.
Just open a new terminal and enter:
$ curl -s "https://get.sdkman.io" | bash
Follow the corresponding instruction prompts, and continue to enter after completing the corresponding operations:
$ source "$HOME/.sdkman/bin/sdkman-init.sh"
Here we can verify The installed version of sdk:
$ sdk version sdk version

The red box mark in the above picture shows my current sdkman version. Every time I execute the sdk version command, I will check whether there is a new version. If you want to update, enter y
Some system releases do not include zip and unzip. If you encounter related errors during installation, you can enter the following command to install zip and unzip
$ sudo apt-get install zip unzip
Installation from above As can be seen from the command, the default installation path of sdkman is under $HOME/.sdkman. We can also customize the installation path by specifying the SDKMAN_DIR variable value:
$ export SDKMAN_DIR="/usr/local/sdkman" && curl -s "https://get.sdkman.io" | bash
The installation of sdkman is over here, let’s take a look at how to use it
sdkman tutorial
To learn a new thing from the command line, of course, check its help Command, enter:
$ sdkman help sdk help[object Object]
I feel that after the above picture distinguishes the content by color, the instructions for using sdkman are over. Let’s follow the above picture to explain the usage tutorial in detail
sdk list
First enter:
$ sdk list sdk list[object Object]
The green marks are all available candidates integrated by sdkman. By pressing the "enter" button, you will see more Available candidate
We specify the candidate, enter:
$ sdk list java sdk list java[object Object]
From the above picture you can see all the available versions of java, as well as the identifier and status. I have installed java 12 and 11
With this information as a basis, we can install any built-in software development package of sdkman, continue to use java as an example
sdk install
Looking back at the output of the sdkman help command, using the install command, we install another Java latest 13.0.1.j9 version

As you can see from the above picture , the green marked content is the version value in the list command result, but the error is unavailable. Enter the indentifier number to download normally. It should be noted here that
After the installation is completed, the status will program the installed status
sdk current
When installing multiple versions of java, we enter the following command to get the version currently using candidate
$ sdk current java sdk current java

sdk use
Understand the current version. If we want to switch to another version, we can enter:
$ sdk use java 12.0.2.j9-adpt
Note⚠️: The same here Is the value of the specified indentifier

sdk default
如果我们想指定某个版本为默认版本,可以输入:
$ sdk default java jdk1.8.0_162.jdk
注意⚠️: 这里同样是指定的 indentifier 的值

sdk uninstall
当我们想卸载某个版本可以输入:
$ sdk uninstall java 12.0.2.j9-adpt
注意⚠️: 这里同样是指定的 indentifier 的值
sdk upgrade
如果我们想升级某个 candidate,可以输入:
$ sdk upgrade java sdk flush
使用 sdkman 时间变长也会慢慢产生很多缓存内容,我们可以输入
清理广播消息:
$ sdk flush broadcast
清理下载的 sdk 二进制文件(长时间使用后清理,可以节省出很多空间):
$ sdk flush archives
清理临时文件内容:
$ sdk flush temp
到这里 sdkman 的基本使用就已经介绍完了,其实这些命令都不用急,想不起来的时候执行 sdk help 来临时查看一下就好
sdkman 卸载
如果我们不喜欢 sdkman 了,我们也可以轻松的卸载掉它:
$ tar zcvf ~/sdkman-backup_$(date +%F-%kh%M).tar.gz -C ~/ .sdkman $ rm -rf ~/.sdkman
最后打开你的 .bashrc、.bash_profile 和/或者 .profile,找到并删除下面这几行。
#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!! [[ -s "/home/dudette/.sdkman/bin/sdkman-init.sh" ]] && source "/home/dudette/.sdkman/bin/sdkman-init.sh"
我用的 zshrc,找到 .zshrc 文件删除掉上面内容即可
到这里基于 Unix 系统的,有关 sdkman 的安装,使用及下载都已经介绍完了,可以上手试一试了
本文来自php中文网,java教程栏目,欢迎学习!
The above is the detailed content of Flexible switching and management of multiple java versions. For more information, please follow other related articles on the PHP Chinese website!
How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?Mar 17, 2025 pm 05:46 PMThe article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.
How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?Mar 17, 2025 pm 05:45 PMThe article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.
How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?Mar 17, 2025 pm 05:44 PMThe article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra
How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?Mar 17, 2025 pm 05:43 PMThe article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]
How does Java's classloading mechanism work, including different classloaders and their delegation models?Mar 17, 2025 pm 05:35 PMJava's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.






