preamble
Recently, the front- and back-end of the project was upgraded, requiring the use of theSwitch between jdk8 and jdk17 versions. The simplest is by manual switching, but the switching process is too cumbersome to modify the environment variables to achieve the switching purpose. So try other solutions, and finally do use sdkman tool.
sdkman It is a product forA command line tool for Java developers designed to simplify themanipulatesystematicallySDKs management. It supports cross-platform use, provides convenient version control and switching functions, and enables users to easily install, update and uninstall various software development kits by maintaining a list of candidate SDKs.
The following is a detailed descriptionInstallation process under windows and linux.
(1)、Windows Installation
at the present time There are two ways to install Windows, WSL and Git Bash. Git should be installed on everyone's computer, so the following is based on Git Bash.sdkman 。
1. Pre-installation preparation:first install sdkman will use the unzip, zip, curl, sed, Git lacks zip:
zip -v
If not found.downloading zip package:
/projects/gnuwin32/files/zip/3.0/
After downloading, unzip the bin directory into the mingw64/bin directory in your Git installation directory:
at the same time zip also depends on bzip2, so download the bzip2 package as well:
/projects/gnuwin32/files/bzip2/1.0.5/
After downloading, unzip the bin directory into the mingw64/bin directory in your Git installation directory:
Then try again. zip command, you can see that it's already working:
2. Install sdkman:acceptdownload and install sdkman in Do the following in Git Bash:
curl -s "" | bash
After the installation is complete, set the sdkman Add it to the environment variables:
source "$HOME/.sdkman/bin/"
Automatically loaded each time the terminal is started sdkman, add the following line to the.zshrcDocumentation:
echo 'source "$HOME/.sdkman/bin/"' >> ~/.zshrc
reload .zshrc:
source ~/.zshrc
Validate the environment:
sdk version
3、sdkman Use
3.1 Viewing all available SDKs
sdk list
One can see a very large number of applications not limited to the JDK 。
3.2 View all available SDKs of the specified type:
sdk list java
3.3 Install the SDK for the specified type of version:
sdk install java 21.0.2-open
3.4 Switching and Using the SDK for a Specified Type of Version
sdk use java 21.0.2-open
validate (a theory) java version:
java --version
3.5 Setting the default version
sdk default java 21.0.2-open
3.6 Viewing the Currently Used SDK
sdk current
3.7 Viewing the Currently Used SDK of a Specified Type
sdk current java
3.8 Viewing the SDK Installation Directory
sdk home java 21.0.2-open
3.8 Uninstalling a Specified Type Version of the SDK
sdk uninstall java 21.0.2-open
3.9 Upgrading sdkman
sdk selfupdate
(2)、Linux installation sdkman
cap (a poem)The installation process is the same under Windows, linux system lacks some commands by default, we need to install them in advance.
2.1. need to install curl, unzip, zip
sudo apt-get install curl
sudo apt-get install unzip
sudo apt-get install zip
2.2 Install sdkman
curl -s "" | bash
2.3 Execute after installation is complete
source "$HOME/.sdkman/bin/"
2.4 Validation
sdk version
sdkman automatically sets the appropriate environment variables. If you want to ensure that the version of Java set by sdkman is used in all terminal sessions, you can set the JAVA_HOME environment variable manually. Add the following line to the .zshrc file:
export JAVA_HOME="$HOME/.sdkman/candidates/java/current"
export PATH="$JAVA_HOME/bin:$PATH"
reload .zshrc:
source ~/.zshrc
(3), Frequently Asked Questions:
cmd command window directly java -version can not find the command, you need to set the path in the environment variable:
The JDK installation path is by default in $HOME/.sdkman/candidates/java/current/bin, the exact path can be viewed in Git Bash with the command:
echo "$HOME/.sdkman/candidates/java/current/bin"
/c/Users/XXX/.sdkman/candidates/java/current/bin
Notes:XXX is your username.
3.1Configuring Environment Variables
Procedure: My Computer- "Right-click Properties - "Advanced System Settings - "Environment Variables - "System Environment - "System Variables:
Add: JAVA_HOME:C:\Users\Administrator\.sdkman\candidates\java\current
Add in Path:%JAVA_HOME%\bin
3.2Verify that it is in effect
Open a terminal and typejava -version to verify that it is the version you just installed.
java -version
(4) Uninstall sdkman
4.1. Deleting the sdkman directory
removing sdkman installation directory:
rm -rf ~/.sdkman
4.2. Removing the sdkman configuration from the configuration file
editorial shell configuration file (e.g. .zshrc), removing lines related to sdkman:
nano ~/.zshrc
Locate and delete the following lines:
source "$HOME/.sdkman/bin/"
export JAVA_HOME="$HOME/.sdkman/candidates/java/current"
export PATH="$JAVA_HOME/bin:$PATH"
Save and exit (in the (Use Ctrl+X in nano and press Y to confirm saving).
4.3. Reloading the shell configuration file
After deleting the configuration line, reload the shell configuration file:
source ~/.zshrc
(5), jdk version selection
Jdk list java listedjdk version, are extended on openJdk, the basic functions are similar, according to the need to download their own, currently used in the development process is mainly jdk8, jdk17, jdk21, etc., such as in my computer to install the three versions:8.0.422-zulu、17.0.12-zulu、21.0.2-open。
Switch to21, the following two commands need to be executed:
sdk use java 21.0.2-open
sdk default java 21.0.2-open
Download the installation package at:C:\Users\Administrator\.sdkman\tmp directory
Mounting Location:C:\Users\Administrator\.sdkman\candidates\java directory
Current is the current jdk in use.
Tip:Just starting the installation.sdkman selects the specified directory on the d drive, but theThe zshrc file modification configuration didn't work, tossed it around for half a day, and finally switched back to the default path. I don't know why, didn't study .....
(6)、idea configuration
Attention:Idea in the configuration of jdk, and manual installation of the same settings, set to the current directory does not work, after the switch, can not automatically switch. So if you need to switch between the various jdk versions, it is best to select all in the sdk, sdkman switch, idea manually and then select the next:
Sdks are added on:
Project specifies the jdk currently in use:
Launching the portal.The jdk also needs to be switched over manually if it hasn't been changed over:
At this point, the installationsdkman manages multiple jdk versions and the process of using them in an idea is complete.
In the installation process, you may encounter other problems, different system environments, the problem may not be the same, according to the different problems to find a solution to realize theThe purpose of sdkman for jdk management.
sdkman tool, is very good cross-platform management jdk tool, hope to help switch jdk trouble you!
Reference Article:
/crazywkl/article/details/142353085
/qq_43692950/article/details/140816049