1. Download JDK7 (i downloaded the Java SE Platform (JDK) 7u51):
http://www.oracle.com/technetwork/java/javase/downloads/index.html
2. Unzip the downloaded compressed package to any location in the system (I usually unzip to/usr/local/)
3, edit/etc/profile, add the following environment variables in the last side (Java_home value depends on the 2nd step decompression path):
Export java_home=/usr/local/jdk1.7.0_51
Export JRE_HOME=${JAVA_HOME}/JRE
Export Classpath=.:${java_home}/lib:${jre_home}/lib
Export Path=${java_home}/bin: $PATHSave exit.
4. Configure the JDK version (depending on the decompression path of the second step):
sudo update-alternatives--install/usr/bin/java Java/usr/local/jdk1.7.0_51/bin/java 300
sudo update-alternatives--install/usr/bin/javac Javac/usr/local/jdk1.7.0_51/bin/javac 300
sudo update-alternatives--install/usr/bin/jar jar/usr/local/jdk1.7.0_51/bin/jar sudo update-alternatives--config java
5. Terminal operation after reboot
Java-version
You can see a new version of Java that is configured in the system
Ubuntu installs Oracle latest JDK7