1. First go to the oracle official website to download the linux version of JDK1.7. The picture below is the JDK1.7 version I downloaded.
2. Drag the JDK compressed package to ubuntu and decompress it. The following operations are all performed under the root user.
sudo tar zxvf jdk-7u
80- linux-x64.tar.gz The following picture is the decompressed folder
3. After decompression, a folder will appear, where we perform the following operations
mkdir /usr/lib/java (just to store the folder we unzipped)
Move the folder we unzipped
mv jdk1.7.0_80 /usr/lib/java
The last step after the move is complete
4.
gedit /etc/profile
After opening the profile, add this sentence at the end
#set java environment
export JAVA_HOME=/usr/lib/java/jdk1.7.0_80
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
export JAVA_HOME=/usr/lib/java/jdk1.7.0_80
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
5. Finally restart Ubuntu
reboot
After the restart is complete, open the terminal and enter java -version to see the following figure. You're done! ! !