Download the latest JDK version from Oracle with
After downloading to get the file jdk-8u101-linux-x64.tar.gz (the file name may be different, the download extension is. tar.gz), the command line to enter the following code to extract the file to the current directory, you will get a folder named Jdk1.8.0_101
TAR-ZXVF jdk-8u101-linux-x64.tar.gz
Create a new folder in the/usr/lib directory Java (requires root access)
Cd/usr/libsudo mkdir Java
Move Folder jdk1.8.0_101/to/usr/lib/java/
sudo mv jdk1.8.0_101//usr/lib/java
Then enter the following 3-line command
sudo update-alternatives--install "/usr/bin/java" "java" "/usr/lib/java/jdk1.8.0_101/bin/java" 1sudo Update-alternatives--install "/usr/bin/javac" "Javac" "/usr/lib/java/jdk1.8.0_101/bin/javac" 1sudo Update-alternatives--install "/usr/bin/javaws" "Javaws" "/usr/lib/java/jdk1.8.0_101/bin/javaws" 1
Finally, set the environment variable, you need to edit the. bashrc file
sudo gedit ~/.BASHRC
Save it at the end of the file by adding 3 lines
#JAVA HOME Directory Setup
Export java_home=/usr/lib/java/jdk1.8.0_101
Export path= "$PATH: $JAVA _home/bin"
Finally, the command line input java-version Test installation success!
Ubuntu 14.04 Installing Java JDK (6 steps)