sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
#Change the number 8 to 6 (or 7) in the code to install Java 6 (or 7).
sudo apt-get install oracle-java8-set-default
# list alternatives
# http://askubuntu.com/questions/521145/how-to-install-oracle-java-on-ubuntu-14-04
sudo update-alternatives --display java
#set JAVA_HOME
sudo vim /etc/environment
# include JAVA_HOME="/usr/lib/jvm/java-8-oracle"