Here are the commands
sudo add-apt-repository ppa:webupd8team/java -y
sudo apt-get update
sudo apt-get install oracle-java8-installer
To automatically set up the Java 8 environment variables
sudo apt-get install oracle-java8-set-default
if the first command fails try:
sudo -E add-apt-repository ppa:webupd8team/java -y