[To] http://blog.csdn.net/lipengshuai0507/article/details/17020131
1. First download the latest jdk 64-bit (jdk-7u45-linux-x64.tar.gz)
Download http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html from official website
2.copy jdk-7u45-linux-x64.tar.gz to the/usr/lib/jvm/directory. If there is no jdk folder, create the folder and run the following command::
Sudo mkdir jvm // create a folder jdk
Sudo cp-r ~ /Download/jdk-7u45-linux-x64.tar.gz/usr/lib/jvm // copy the downloaded file to the newly created directory
Sudo tar-zxvg jdk-7u45-linux-x64.tar.gz // Extract files
3. Set environment variables and use nano to open the/etc/profile file.
Sudo nano/etc/profile
Add the following at the end of the file:
Export JAVA_HOME =/usr/lib/jvm/jdk1.7.0 _ 45
Export JRE_HOME =/usr/lib/jvm/jdk1.7.0 _ 45/jre
Export PATH = $ JAVA_HOME/bin: $ JAVA_HOME/jre/bin: $ PATH
Export CLASSPATH = $ CLASSPATH:.: $ JAVA_HOME/lib: $ JAVA_HOME/jre/lib
4. Modify the default jdk of the system.
$ Sudo update-alternatives -- install/usr/bin/java/usr/lib/jvm/jdk1.7.0 _ 45/bin/java 300
$ Sudo update-alternatives -- install/usr/bin/javac/usr/lib/jvm/jdk1.7.0 _ 45/bin/javac 300
$ Sudo update-alternatives -- config java
$ Sudo update-alternatives -- config javac
5. Check and enter java-version
Java version "1.7.0 _ 45"
Java (TM) SE Runtime Environment (build 1.7.0 _ 45-b18)
Java HotSpot (TM) 64-Bit Server VM (build 24.45-b08, mixed mode)