Since Oracle does not provide a native Java installation package for Ubuntu Linux, we can install via distribution created by webupd8 on PPA repository for Java.

First, we need to add PPA and update repository.


$ sudo add-apt-repository ppa:webupd8team/java

$ sudo apt-get update

and then, we can install Java 8 package.


$ sudo apt install oracle-java8-installer

During installation process, there will be a prompt to accept Oracle Java license, just select OK then press Enter. Afterwards, Java is ready, you can verify via this command:


$ javac -version
javac 1.8.0_151

It will print out Java version installed.