First step: Download jdk-7-linux-i586.tar.gz
wget -C http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-i586.tar.gz
(Note: If the download is not down, it is recommended to use Thunderbolt download, and then copied to the Linux system.) )
Step Two: Unzip the installation
sudo tar zxvf./jdk-7-linux-i586. tar. GZ -c/usr/lib/JVM /usr/lib/jvm sudomv jdk1. 7.0/java-7-sun
Step Three: Modify environment variables
Vim ~/.BASHRC
Add to:
Export java_home=/usr/lib/jvm/java-7-Sun export jre_home=${java_home}/JRE Export CLASSPATH=.:${java_home}/lib:${jre_home}/lib export PATH=${java_home}/bin: $PATH
Save the exit and enter the following command to take effect immediately.
Fourth Step: Configure the default JDK version because there may be default JDK in Ubuntu, such as OPENJDK, we do the following to set up our installed JDK as the default JDK version.
Execute code:
sudo update-alternatives--install /usr/bin/java java/usr/lib/jvm/java-7 sudo update-alternatives--install /usr/bin/javac javac/usr/lib/jvm/java-7300
Execute code:
sudo update-alternatives--config java
The various JDK versions are listed as follows:
[Email protected]:~$sudoUpdate-alternatives--config Java has3Candidate can be used to replace Java (provides a/usr/bin/Java). Select Path Priority State------------------------------------------------------------ *0/usr/lib/jvm/java-6-openjdk/jre/bin/java1061Automatic mode1/usr/lib/jvm/java-6-openjdk/jre/bin/java1061Manual Mode2/usr/lib/jvm/java-6-sun/jre/bin/java theManual Mode3/usr/lib/jvm/java-7-sun/bin/java -Manual mode to maintain the current value [*] Press ENTER, or type the number you selected:3Update-alternatives: Using/usr/lib/jvm/java-7-sun/bin/java to provide/usr/bin/java (Java) in manual mode.
Fifth Step: Test
[Email protected]:~$ java-version "1.7.0" 1.7. 0-b147) 21.0
Thank you: http://blog.csdn.net/hzqnju/article/details/6779556