1. Download the jdk installation package of the corresponding system from the Oracle official website:
Java Downloads | Oraclehttps://www.oracle.com/java/technologies/downloads/#java17
Select the corresponding .gz package to download
2. Unzip and put it in the specified directory (take jre-8u361-linux-x64.tar.gz as an example)
1.) Create a directory:
sudo mkdir /usr/local/software/java
2.) Move the jdk file downloaded in the /usr/local/software/java directory to the /usr/local/software/java directory:
sudo mv /usr/local/software/java/jre-8u361-linux-x64.tar.gz /usr/local/software/java
3.) Unzip the installation package to the current directory:
sudo tar -zxvf jre-8u361-linux-x64.tar.gz -C /usr/local/software/java
3. Modify environment variables:
Enter the command to open the configuration file:
sudo vim ~/.bashrc
As shown in the figure, switch to the end of the text content and enter the following content:
#set oracle jdk environment
export JAVA_HOME=/usr/local/software/java/jre1.8.0_361 ## 这里要注意目录要换成自己解压的jdk 目录
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
:wq
Save and exit.
4. Test whether the installation is successful:
Enter at the terminal command line:
java -version
The version number shown below indicates that the installation was successful: