Java upgrade so fast, multiple versions of how flexible switching and management?

Foreword

The past two years, Java version upgrades frequently, feeling just grasp Java8, the time of this writing, has heard the news java14, whether early adopters of new features ( Java12 Collectors.teeing powerful features in use ), or because the project upgrades / compatible needs, we may have to face a situation manage multiple versions of Java

In addition Oracle since Java11 start, change the user agreement, any business will be charged. In writing this article, get the message, "Microsoft announced to join the OpenJDK" beat on the choice of OpenJDK. G casual look, when you can understand the story

Single configuration itself is no technical content Java environment variables to speak of, but need to manage multiple versions of Java, repeat the configuration environment variable is obviously very boring, according to the traditional configuration we can not be flexible switching Java versions

So how to easily manage and use multiple versions of Java?

Multiple versions of Java Management

Obviously we have not the first person this predicament, the existing program that I know of three ways:

  1. Jabba
  2. jenv
  3. sdkman

This article describes how to break the dilemma we face by sdkman, help us to flexibly configured using Java

sdkman Introduction

SDKMAN is for most Unix-based management system on multiple Software Development Kit (Java, Groovy, Scala, Kotlin and Ceylon. Ant, Gradle , etc.) of a parallel version of the tool.

It provides a convenient command-line interface (CLI) and the API, for 安装, 切换, 删除and 列出候选对象. In this paper, through the management of Java to illustrate the use sdkman

sdkman installation

Sdkman installed on the unix-platform very easily. It can be successfully installed on Mac OSX, Linux, WLS, Cygwin, Solaris and FreeBSD, and also supports Bash and ZSH shell.

Simply open a new terminal and type:

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

According to the corresponding command prompts, and continues after the corresponding operation input:

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

Here we can verify the installed version of the sdk:

$ sdk version

sdk version

The figure marked a red box displays the version of my current sdkman, each execution sdk versioncommand, checks whether there will be a new version, if you want to update the input ycan be

Some systems release does not contain zipand unzip, encounters an error during installation, you can enter the following command to install zipandunzip

$ sudo apt-get install zip unzip

As can be seen from the above setup command, sdkman default installation path is $HOME/.sdkmanunder, we can customize the installation path, only need to specify SDKMAN_DIRthe variable value like:

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

Here sdkman the installation is over, let's look at how you can use

sdkman Tutorial

Command line to learn a new thing of course is to look at its help command, enter:

$ sdkman help

sdk help

After feeling by color-coded content, sdkman instructions for use will be over the map, we follow the above diagram to elaborate tutorial

sdk list

First to enter:

$ sdk list

sdk list

Green mark is sdkman integration of all available candidate, by pressing the Enter "enter" button, you will see more available candidate

We designated candidate, enter:

$ sdk list java

sdk list java

You can see all the available versions of java version, and the identification indentifier, as well as state status from the image above, I have to install the java 12 and 11

With this information to pave the way, we can install any sdkman built-in software development kit, and continue to be an example java

sdk install

Looking back at sdkman help command output, use the install command, we install a new Java 13.0.1.j9version

From the chart you can see the contents of the green-labeled version is the value list in the command result, but the error is not available, enter the indentifiernumber to download normal to note here

After installation, status will be installed state program

sdk current

When installing multiple versions of java, we enter the following command to obtain the version currently being used in candidate

$ sdk current java

sdk current java

sdk use

Learn to use the current version, if we want to switch to a different version, you can enter:

$ sdk use java 12.0.2.j9-adpt

Note ⚠️: Here, too, is the value of the specified indentifier

sdk default

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

$ sdk default java jdk1.8.0_162.jdk

Note ⚠️: Here, too, is the value of the specified indentifier

sdk uninstall

When we want to uninstall a version can be entered:

$ sdk uninstall java 12.0.2.j9-adpt

Note ⚠️: Here, too, is the value of the specified indentifier

sdk upgrade

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

$ sdk upgrade java

sdk flush

Use sdkman time becomes longer will gradually produce a lot of cache content, we can enter
to clean up the broadcast message:

$ sdk flush broadcast

Cleanup sdk download binary file (cleaning up after prolonged use, you can save a lot of space):

$ sdk flush archives

Clean up temporary files Content:

$ sdk flush temp

Here's the basic use sdkman have been introduced over, in fact, these commands do not worry, can not remember when the execution sdk helpcomes look like

sdkman Uninstall

If we do not like sdkman, and 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 WORK!!!
[[ -s "/home/dudette/.sdkman/bin/sdkman-init.sh" ]] && source "/home/dudette/.sdkman/bin/sdkman-init.sh"

I use zshrc, find .zshrc file content can be removed above

Here to Unix-based system, the relevant sdkman installation, use and downloads have been introduced over, we can try to get started, and I believe that many small partners are using Windows, in addition to jenv, sdkman and Jabba has windows user solutions:

sdkman windows Solution

Also provides solutions for windows users sdkman official website home page, find little friends can view the following location

I looked at the process is very simple, because the windows do not have a computer, this small partners please try it on their own, there are questions please leave a message

Soul questioning

  1. Java version you use now is how much?
  2. There followed a new version to try more new feature?
  3. Your lights on it?

    Welcome to continued public concern number: "arch day a soldier."

    • Dry cutting-edge Java technology sharing
    • Productivity tools summary | Reply "Tools"
    • Analysis of interview questions and answers
    • Technical Data collection | Reply "Information"

Easy to read detective novels thinking fun learning Java technology stack-related knowledge, in line with the simplification of complex issues, problems specific abstract and graphical decomposition of the principle of progressive technical issues, technology continues to update, please stay tuned ......


Guess you like

Origin www.cnblogs.com/FraserYu/p/11880130.html