Oracle Java 7
1. Add PPA and install Java
sudo add-apt-repository ppa:webupd8team/java
If this command gives you an error then the solution is to install the python-software-properties package:
$ sudo apt-get install python-software-properties
sudo apt-get update && sudo apt-get install oracle-jdk7-installer
2. Enable Java
update-alternatives –display java
3. Check installation
java -version
4. Adding JAVA_HOME to environment
Edit /etc/environment and add JAVA_HOME=/usr/lib/jvm/java-7-oracle to the end of the file.
sudo nano /etc/environment
Append to the end of the file:
JAVA_HOME=/usr/lib/jvm/java-7-oracle
Sun Java 6
sudo apt-get install python-software-properties
sudo add-apt-repository “deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main”
sudo apt-get update
sudo apt-get install sun-java5-jdk sun-java6-jdk