1, first uninstall the server's own JDK package
# java-version #查看服务器是否安装过jdk
Java Version "1.6.0_17"
OpenJDK Runtime Environment (IcedTea6 1.7.4) (rhel-1.21.b17.el6-i386)
OpenJDK Client VM (build 14.0-b16, Mixed mode)
# Rpm-qa |grep gcj #查看服务器安装的jdk软件包信息
libgcj-4.4.4-13.el6.i686
java-1.5.0-gcj-1.5.0.0-29.1.el6.i686
# rpm-e java-1.5.0-gcj-1.5.0.0-29.1.el6.i686 #卸载软件包
2, to the Sun's official website download
Http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
Select Accept License and select the JDK download that fits your model.
3, unzip the file, modify the filename
$ sudo MKDIR/USR/LIB/JVM
$ sudo tar zxvf jdk-7u21-linux-i586.tar.gz-c/USR/LIB/JVM
$ CD/USR/LIB/JVM
$ sudo mv jdk1.7.0_21 Java
4. Add Environment variables
$ sudo vim ~/.BASHRC
Add the following:
Export Java_home=/usr/lib/jvm/java
Export JRE_HOME=${JAVA_HOME}/JRE
Export Classpath=.:${java_home}/lib:${jre_home}/lib
Export Path=${java_home}/bin: $PATH
5. Configuring the default JDK version
sudo update-alternatives--install/usr/bin/java Java/usr/lib/jvm/java/bin/java 300
sudo update-alternatives--install/usr/bin/javac Javac/usr/lib/jvm/java/bin/javac 300
sudo update-alternatives--install/usr/bin/jar Jar/usr/lib/jvm/java/bin/jar 300
sudo update-alternatives--install/usr/bin/javah javah/usr/lib/jvm/java/bin/javah 300
sudo update-alternatives--install/usr/bin/javap JAVAP/USR/LIB/JVM/JAVA/BIN/JAVAP 300
And then execute
sudo update-alternatives--config java
If you first install the JDK, you will be prompted
There is only one alternative in link Group Java (providing/usr/bin/java):/usr/lib/jvm/java/bin/java
No configuration required.
For non-initial installation, there will be different versions of the JDK option.
6. Testing
$ java-version
Java Version "1.7.0_21"
Java (TM) SE Runtime Environment (build 1.7.0_21-B11)
Java HotSpot (TM) Server VM (build 23.21-b01, Mixed mode)
JDK Installation (i)