First download linux Installation package under

When the download is complete ,Linux The default download location is... In the current directory Download Or download the folder , Through the command cd ~/Downloads or cd  ~/ Download to view the corresponding file .

Expand :linux Next, open the directory ~ and / The difference between

Unzip the installation package jdk-8u202-linux-x64-demos.tar.gz

 tar -zxvf jdk-8u202-linux-x64-demos.tar.gz

Move the unzipped file to /usr/lib Under the table of contents

Switch to /usr/bin Under the table of contents

 cd /usr/lib

And new jdk Catalog

 sudo mkdir jdk

The jdk Move the file to the new /usr/lib/jdk List it down

 sudo mv ~/jdk1.8.0_202/usr/lib/jdk

After executing the command, you can go to  usr/lib/jdk  Check whether the move is successful under the directory

To configure java environment variable

Here is to configure the environment variables in etc/profile, That is to configure... For all users JDK Environmental Science .

Open with command /etc/profile file

 sudo vim /etc/profile

Add the following lines at the end :

#set java env
export JAVA_HOME=/usr/lib/jdk/jdk1.8.0_202
export JRE_HOME=${JAVA_HOME}/jre    
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib    
export PATH=${JAVA_HOME}/bin:$PATH

Execute the order to make the change effective immediately

 source /etc/profile

Expand : understand ubuntu Environment variables file in /etc/profile、.profile、.bashrc、/etc/bash.bashrc The difference and connection between

Configure soft connection

A soft connection is equivalent to windows Shortcut keys in the system , Some of the software may come from /usr/bin Directory lookup Java, So add the soft connection to prevent the situation that other software can't find .

sudo update-alternatives --install /usr/bin/java  java  /usr/lib/jdk/jdk1.8.0_202/bin/java 300   
sudo update-alternatives --install /usr/bin/javac  javac  /usr/lib/jdk/jdk1.8.0_202/bin/javac 300

Expand : stay Ubuntu Pass through update-alternatives Switch jdk edition

Test the installation for success

Input... At the terminal , The version number indicates that the installation is successful .

 java -version

The result is shown in Fig. :