I’ve seen a couple of ways to do this on the internet but the easiest is through apt-get and ppa.
The catch with doing anything in Java on Ubuntu is always the same - Ubuntu doesn’t ship with Oracle’s Java installed. Instead, Ubuntu ships with Open JDK installed. Open JDK is an open source version of Java. Some may argue that you can develop with and probably run most things Java with Open JDK. That may be the case, but for me I find the Oracle Java to be more trustworthy for production environment so will be using the Oracle bits. This is simply a matter of opinion.
Apt-get needs to be configured to point to a ppa that will take care of the heavy lifting and then install like anything else via apt.
Open a terminal and execute the following:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
Verify Oracle Java 8 is the default java version, the ‘*’ char notes the selected default:
sudo update-alternatives —config java
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
0 /usr/lib/jvm/java-8-oracle/jre/bin/java 1072 auto mode
1 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode
2 /usr/lib/jvm/java-8-oracle/jre/bin/java 1072 manual mode
Press enter to keep the current choice, or type selection number:
That’s it. All done.