Download JDK for Java 8 from Oracle’s web-site. Unpack archive to let’s say /usr/lib/jvm/jdk1.8.0/

Update java alternatives:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.8.0/bin/javaws" 1

Select alternatives:

sudo update-alternatives --config java

Select an option corresponding to new path.

Do the same for

sudo update-alternatives --config javac
sudo update-alternatives --config javaws

Update JAVA_HOME using

gksudo gedit /etc/environment

Don’t forget to rerun terminal or reboot.

Based on this thread