首先查看yum库有哪些jdk安装包可以使用

# yum -y list java*

输出:
Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

* base: mirrors.163.com

* extras: mirrors.163.com

* updates: mirrors.163.com

Installed Packages

java-1.6.0-openjdk.x86_64 1:1.6.0.0-1.49.1.11.4.el6_3 @updates

java-1.6.0-openjdk-demo.x86_64 1:1.6.0.0-1.49.1.11.4.el6_3 @updates

java-1.6.0-openjdk-devel.x86_64 1:1.6.0.0-1.49.1.11.4.el6_3 @updates

java-1.6.0-openjdk-javadoc.x86_64 1:1.6.0.0-1.49.1.11.4.el6_3 @updates

java-1.6.0-openjdk-src.x86_64 1:1.6.0.0-1.49.1.11.4.el6_3 @updates

Available Packages

java-1.5.0-gcj.x86_64 1.5.0.0-29.1.el6 base

java-1.5.0-gcj-devel.x86_64 1.5.0.0-29.1.el6 base

java-1.5.0-gcj-javadoc.x86_64 1.5.0.0-29.1.el6 base

java-1.5.0-gcj-src.x86_64 1.5.0.0-29.1.el6 base

java-1.7.0-openjdk.x86_64 1:1.7.0.5-2.2.1.el6_3.3 updates

java-1.7.0-openjdk-demo.x86_64 1:1.7.0.5-2.2.1.el6_3.3 updates

java-1.7.0-openjdk-devel.x86_64 1:1.7.0.5-2.2.1.el6_3.3 updates

java-1.7.0-openjdk-javadoc.noarch 1:1.7.0.5-2.2.1.el6_3.3 updates

java-1.7.0-openjdk-src.x86_64 1:1.7.0.5-2.2.1.el6_3.3 updates

java_cup.x86_64 1:0.10k-5.el6 base

java_cup-javadoc.x86_64 1:0.10k-5.el6 base

java_cup-manual.x86_64 1:0.10k-5.el6 base

javacc.x86_64 4.1-0.5.el6 base

javacc-demo.x86_64 4.1-0.5.el6 base

javacc-manual.x86_64 4.1-0.5.el6 base

javassist.noarch 3.9.0-6.el6 base

javassist-javadoc.noarch 3.9.0-6.el6 base

安装所有java-1.6.0的jdk包

# yum -y install java-1.6.0-openjdk*

查看是否安装成功

# java -version

输出:

java version "1.6.0_24"

OpenJDK Runtime Environment (IcedTea6 1.11.4) (rhel-1.49.1.11.4.el6_3-x86_64)

OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)