JDK multi-version installation Windows and Linux

JDK multi-version installation Windows and Linux

Multiple versions of jdk are installed on Windows, if adjusting environment variables does not take effect, go directly to the end

Go to the official website to download jdk

The previous official website download address:
https://www.java.com/zh-CN/download/Because
it was acquired by Oracle, now it will go to Oracle to download: https://www.oracle.com/java/technologies/downloads /archive/

All releases can be found on the right, download the required version:
jdk download

You can download the exe version or the compressed version. You don’t need to install the compressed version. You can directly unzip it to the directory you created to configure the environment variables and skip the next step.
The two installation methods are similar!

Install jdk to this machine

1. Run the installer, the next step is the default, here you can change the default installation location of JDK:

Change the installation directory during installation

2. Install jre

After the installation of jdk is completed, a dialog box for installing jre will pop up. This jre can also change the installation location. It is recommended to install it in the same parent directory as jdk. Although jre comes with jdk, this jre still needs to be installed.
Change jre installation directory
It can be used after the installation is complete, but it is generally necessary to configure environment variables during development.

set environment variables

1. Enter environment variables

This Computer => Properties => Advanced System Settings => Advanced => Environment Variables
environment variable entry
Environment variable settings

Create a new modification in the system variable! It's the one below! Note that all punctuation marks are in English.
environment variable

2. New: JAVA_HOME

Variable value: the installed JDK directory
Description: This is convenient for later development and use
JAVA_HOME

3. New: CLASSPATH

Variable value: .;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar
Description: Paths of various jar packages
CLASSPATH

4. Edit the path variable value

Find the path, double-click this one to edit:
path

path
Create two new

%JAVA_HOME%\bin
%JAVA_HOME%\jre\bin

Environment variables set
save!
Be sure to save!

Check installation status

Check whether the Java environment variable is set successfully in cmd

java -version

cmd verify Java version
After reading the version, you can also write a hello word and try it out!

So far, the work is not finished... If you have installed multiple versions, the first method is the same, but the environment variable does not need to be set, but there will be a problem that the environment variable is modified, but the cmd does not take effect, just see the following.

Remark

You can also download the compressed file directly, unzip and configure the environment variables.

Install under Linux

Download the compressed package of the corresponding version, unzip it to the directory you want to install, and configure the environment variable:
modify the /etc/profile file

 sudo vim /etc/profile

Shift+g jumps to the end of the file and appends:

JAVA_HOME=安装目录
export JRE_HOME=$JAVA_HAOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$PATH

Refresh the variables: (restart is also possible)

source /etc/profile

It can be
viewed in the terminal using java -version

Windows multi-version JDK modification of environment variables does not take effect

This is also a common pit. After installing multiple versions of jdk at the same time, it turns out that after modifying the value of JAVA_HOME, it is still the last installed version in cmd. This is because java.exe, javaw.exe, The three javaws.exe files are placed in the system directory, and the priority in the environment variable is higher than that set by ourselves, so it will run here.

C:\ProgramData\Oracle\Java\javapath

或者是

C:\Windows\System32

Mine is in the first path, just delete it (does not affect the normal development and use), should I say nothing, the software Everything is easy to use, and I will have a chance to publish a guide on the use of Everything later.
java path
permission prompt
It will return to normal after deletion.

Guess you like

Origin blog.csdn.net/qq_39950529/article/details/123536726