1. Put the downloaded jdk1.8.0_161.tar.gz in the ubuntu directory /usr/java directory
2. Unzip: tar -zxvf jdk1.8.0_161.tar.gz
3. Set environment variables:
You can choose to modify the global configuration file for all users or modify the current user configuration file, only for the current user, the former I choose, modify the /etc/profile file, vi /etc/profile, and add at the bottom:
export JAVA_HOME=/usr/java/jdk1.8.0_161
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=.:${JAVA_HOME}/bin:$PATH
4. Make the modified configuration take effect immediately: source /etc/profile
5. Check if the installation is successful: java -version