Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to flexibly switch and manage multiple versions of Java

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to flexibly switch and manage multiple versions of Java". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to flexibly switch and manage multiple versions of Java.

Sdkman introduction

SDKMAN is a tool for managing multiple software development kits (Java, Groovy, Scala, Kotlin and Ceylon. Parallel version of the tool for Ant, Gradle, etc.

It provides a convenient command line interface (CLI) and API for installing, switching, deleting, and listing candidates. This article mainly explains the use of sdkman by managing Java.

Sdkman installation

Installing sdkman on a unix-like platform is very easy. It can be installed smoothly on Mac OSX, Linux, WLS, Cygwin, Solaris and FreeBSD, and also supports Bash and ZSH shell.

Just open a new terminal and type:

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

Follow the corresponding instructions and continue to enter after completing the corresponding operation:

$source "$HOME/.sdkman/bin/sdkman-init.sh"

At this point, we can verify the installation version of sdk:

$sdk version

The red box above shows my current version of sdkman. Every time I execute the sdk version command, I will check whether there is a new version. If you want to update the input y, you can.

Some system distributions 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

As can be seen from the above installation command, the default installation path for sdkman is under $HOME/.sdkman. We can also customize the installation path by specifying the value of the SDKMAN_DIR variable:

$export SDKMAN_DIR= "/ usr/local/sdkman" & & curl-s "https://get.sdkman.io" | bash

At this point, the installation of sdkman is over. Let's take a look at how to use the

Sdkman usage tutorial

To learn a new gadget from the command line, of course, look at its help command and type:

$sdkman help

It seems that after the above picture distinguishes the content by color, the instructions for using sdkman will come to an end. Let's use the tutorial in detail according to the figure above.

Sdk list

First, enter:

$sdk list

The green mark is all available candidate integrated by sdkman. By pressing enter "enter" button, you will see more available candidate.

We specify candidate and enter:

$sdk list java

From the figure above, you can see all the available versions of java, version, as well as identity indentifier, and status status. I have installed java 12 and 11.

With this information as the groundwork, we can install any sdkman built-in software development package, and continue to take java as an example

Sdk install

Looking back at the output of the sdkman help command, using the install command, we install the latest 13.0.1.j9 version of Java

As you can see from the above picture, the green mark is the version value in the result of the list command, but the error is not available. Enter the indentifier number to download normally. Note here.

After installation, status will program the installed state

Sdk current

When installing multiple versions of java, we enter the following command to get the version of candidate that is currently in use

$sdk current java

Sdk use

Knowing the current version, if we want to switch to another version, we can enter:

$sdk use java 12.0.2.j9-adpt

Note ⚠️: this is also the value of the specified indentifier

Sdk default

If we want to specify a version as the default version, we can enter:

$sdk default java jdk1.8.0_162.jdk

Note ⚠️: this is also the value of the specified indentifier

Sdk uninstall

When we want to uninstall a version, we can type:

$sdk default java jdk1.8.0_162.jdk

Note ⚠️: this is also the value of the specified indentifier

Sdk upgrade

If we want to upgrade a candidate, we can enter:

$sdk upgrade javasdk flush

Using sdkman for a longer time will also slowly generate a lot of cached content, we can enter

Clean up broadcast messages:

$sdk flush broadcast

Clean up downloaded sdk binaries (after long use, you can save a lot of space):

$sdk flush archives

Clean up the contents of the temporary file:

$sdk flush temp

At this point, the basic use of sdkman has been introduced. In fact, there is no need to worry about these commands. When you can't remember, just execute sdk help and check it out.

Sdkman uninstall

If we don't like sdkman, we can easily uninstall it:

$tar zcvf ~ / sdkman-backup_$ (date +% F-%kh%M). Tar.gz-C ~ / .sdkman $rm-rf ~ / .sdkman

Finally, open your .bashrc, .bash _ profile and / or .profile, find and delete the following lines.

# THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO working hours! [[- s "/ home/dudette/.sdkman/bin/sdkman-init.sh"]] & & source "/ home/dudette/.sdkman/bin/sdkman-init.sh"

I use zshrc. Just find the .zshrc file and delete it.

Here, based on the Unix system, the installation, use and download of sdkman have been introduced, so you can try it. I believe many partners use Windows. In addition to jenv, sdkman and Jabba all have solutions for windows users:

Sdkman windows solution

The home page of sdkman official website also provides a solution for windows users. Friends can find the following location to check it out.

I took a look at the process, it is also very simple, as there is no windows computer on hand, please try this by yourself.

At this point, I believe you have a deeper understanding of "how to flexibly switch and manage multiple versions of Java". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report