Installing Oracle's Java in Ubuntu

Create a root level opt directory.

$ sudo mkdir /opt

Download the JRE or JDK from Oracle as a tar file and uncompress it into /opt

$ cd /opt
$ sudo tar xvfz jdk-8u191-linux-x64.tar.gz

Create link to it, making it easier to replace this version of Java when it needs to be updated.

$ sudo ln -s java jdk1.8.0_191

Add this as a default command for Ubuntu (javac is only if you downloaded the JDK).

$ sudo update-alternatives --install /usr/bin/java java /opt/java/bin/java 1
$ sudo update-alternatives --install /usr/bin/javac javac /opt/java/bin/javac 1

Now the java and javac command should be available.

$ java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
$ javac -version
javac 1.8.0_191