System version: Ubuntu 16.04
JDK version: jdk1.8.0_121
1. Download the JDK file jdk-8u121-linux-x64.tar.gz from the official website
I downloaded the latest version here, other versions are also available
2. Create a directory as the JDK installation directory, my directory is /java
java is a system file, just create the /java folder directly in the root directory
sudo mkdir /java
3. Move the file to the /java directory
sudo mv jdk-8u121-linux-x64.tar.gz /java
4. Unzip the file
tar -zxvf jdk-8u121-linux-x64.tar.gz
5. Configure environment variables for all users
sudo gedit /etc/profile
Add the following at the end of the file:
#set Java environment
export JAVA_HOME=/dengyang/jdk1.8.0_56
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
Save and close after modification
6. Enter java -version to display the JDK version description Congratulations, the environment variables are configured correctly