1.查看CentOS自带JDK是否已安装。
yum list installed |grep java。
2.卸载原有JDK
yum -y remove java-1.5.0-gcj.i686
3.查看yum库中的JDK包
yum -y list java*
4.安装JDK
yum -y install java-1.8.0-openjdk.i686
[root@VM_238_215_centos ~]# yum list installed |grep java java-1.5.0-gcj.i686 1.5.0.0-29.1.el6 @os [root@VM_238_215_centos ~]# yum -y remove java-1.5.0-gcj.i686 Loaded plugins: fastestmirror, security Setting up Remove Process Resolving Dependencies --> Running transaction check ---> Package java-1.5.0-gcj.i686 0:1.5.0.0-29.1.el6 will be erased --> Processing Dependency: java-gcj-compat >= 1.0.70 for package: sinjdoc-0.5-9.1.el6.i686 --> Processing Dependency: java-gcj-compat >= 1.0.70 for package: sinjdoc-0.5-9.1.el6.i686 --> Running transaction check ---> Package sinjdoc.i686 0:0.5-9.1.el6 will be erased --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================ Package Arch Version Repository Size ============================================================================================================ Removing: java-1.5.0-gcj i686 1.5.0.0-29.1.el6 @os 140 k Removing for dependencies: sinjdoc i686 0.5-9.1.el6 @os 2.0 M Transaction Summary ============================================================================================================ Remove 2 Package(s) Installed size: 2.1 M Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Warning: RPMDB altered outside of yum. Erasing : sinjdoc-0.5-9.1.el6.i686 1/2 Erasing : java-1.5.0-gcj-1.5.0.0-29.1.el6.i686 2/2 Verifying : java-1.5.0-gcj-1.5.0.0-29.1.el6.i686 1/2 Verifying : sinjdoc-0.5-9.1.el6.i686 2/2 Removed: java-1.5.0-gcj.i686 0:1.5.0.0-29.1.el6 Dependency Removed: sinjdoc.i686 0:0.5-9.1.el6 Complete! [root@VM_238_215_centos ~]# yum list installed |grep java [root@VM_238_215_centos ~]# java -version -bash: /usr/bin/java: No such file or directory [root@VM_238_215_centos ~]# yum -y list java* Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile Available Packages java-1.5.0-gcj.i686 1.5.0.0-29.1.el6 os java-1.5.0-gcj-devel.i686 1.5.0.0-29.1.el6 os java-1.5.0-gcj-javadoc.i686 1.5.0.0-29.1.el6 os java-1.5.0-gcj-src.i686 1.5.0.0-29.1.el6 os java-1.6.0-openjdk.i686 1:1.6.0.41-1.13.13.1.el6_8 os java-1.6.0-openjdk-demo.i686 1:1.6.0.41-1.13.13.1.el6_8 os java-1.6.0-openjdk-devel.i686 1:1.6.0.41-1.13.13.1.el6_8 os java-1.6.0-openjdk-javadoc.i686 1:1.6.0.41-1.13.13.1.el6_8 os java-1.6.0-openjdk-src.i686 1:1.6.0.41-1.13.13.1.el6_8 os java-1.7.0-openjdk.i686 1:1.7.0.131-2.6.9.0.el6_8 os java-1.7.0-openjdk-demo.i686 1:1.7.0.131-2.6.9.0.el6_8 os java-1.7.0-openjdk-devel.i686 1:1.7.0.131-2.6.9.0.el6_8 os java-1.7.0-openjdk-javadoc.noarch 1:1.7.0.131-2.6.9.0.el6_8 os java-1.7.0-openjdk-src.i686 1:1.7.0.131-2.6.9.0.el6_8 os java-1.8.0-openjdk.i686 1:1.8.0.131-0.b11.el6_9 updates java-1.8.0-openjdk-debug.i686 1:1.8.0.131-0.b11.el6_9 updates java-1.8.0-openjdk-demo.i686 1:1.8.0.131-0.b11.el6_9 updates java-1.8.0-openjdk-demo-debug.i686 1:1.8.0.131-0.b11.el6_9 updates java-1.8.0-openjdk-devel.i686 1:1.8.0.131-0.b11.el6_9 updates java-1.8.0-openjdk-devel-debug.i686 1:1.8.0.131-0.b11.el6_9 updates java-1.8.0-openjdk-headless.i686 1:1.8.0.131-0.b11.el6_9 updates java-1.8.0-openjdk-headless-debug.i686 1:1.8.0.131-0.b11.el6_9 updates java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.131-0.b11.el6_9 updates java-1.8.0-openjdk-javadoc-debug.noarch 1:1.8.0.131-0.b11.el6_9 updates java-1.8.0-openjdk-src.i686 1:1.8.0.131-0.b11.el6_9 updates java-1.8.0-openjdk-src-debug.i686 1:1.8.0.131-0.b11.el6_9 updates java-clearsilver.i686 0.10.5-16.el6 epel java-dirq.noarch 1.4-1.el6 epel java-dirq-javadoc.noarch 1.4-1.el6 epel java-service-wrapper.i686 3.2.5-23.el6 epel java-service-wrapper-javadoc.noarch 3.2.5-23.el6 epel java-sleep.noarch 2.1-6.el6 epel java-sleep-javadoc.noarch 2.1-6.el6 epel java_cup.i686 1:0.10k-5.el6 os java_cup-javadoc.i686 1:0.10k-5.el6 os java_cup-manual.i686 1:0.10k-5.el6 os javacc.i686 4.1-0.5.el6 os javacc-demo.i686 4.1-0.5.el6 os javacc-manual.i686 4.1-0.5.el6 os javassist.noarch 3.9.0-6.el6 os javassist-javadoc.noarch 3.9.0-6.el6 os javastroke.i686 0.5.1-33.el6 epel javatar.noarch 2.5-5.el6 epel javatar-javadoc.noarch 2.5-5.el6 epel [root@VM_238_215_centos ~]# yum -y install java-1.8.0-openjdk.i686 Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package java-1.8.0-openjdk.i686 1:1.8.0.131-0.b11.el6_9 will be installed --> Processing Dependency: java-1.8.0-openjdk-headless = 1:1.8.0.131-0.b11.el6_9 for package: 1:java-1.8.0-openjdk-1.8.0.131-0.b11.el6_9.i686 --> Processing Dependency: xorg-x11-fonts-Type1 for package: 1:java-1.8.0-openjdk-1.8.0.131-0.b11.el6_9.i686 --> Processing Dependency: libjvm.so(SUNWprivate_1.1) for package: 1:java-1.8.0-openjdk-1.8.0.131-0.b11.el6_9.i686 --> Processing Dependency: libjli.so(SUNWprivate_1.1) for package: 1:java-1.8.0-openjdk-1.8.0.131-0.b11.el6_9.i686 --> Processing Dependency: libjli.so for package: 1:java-1.8.0-openjdk-1.8.0.131-0.b11.el6_9.i686 --> Processing Dependency: libjava.so(SUNWprivate_1.1) for package: 1:java-1.8.0-openjdk-1.8.0.131-0.b11.el6_9.i686 --> Processing Dependency: libjava.so for package: 1:java-1.8.0-openjdk-1.8.0.131-0.b11.el6_9.i686 --> Processing Dependency: libgif.so.4 for package: 1:java-1.8.0-openjdk-1.8.0.131-0.b11.el6_9.i686 --> Processing Dependency: libawt.so for package: 1:java-1.8.0-openjdk-1.8.0.131-0.b11.el6_9.i686 --> Running transaction check ---> Package giflib.i686 0:4.1.6-3.1.el6 will be installed ---> Package java-1.8.0-openjdk-headless.i686 1:1.8.0.131-0.b11.el6_9 will be installed --> Processing Dependency: tzdata-java >= 2014f-1 for package: 1:java-1.8.0-openjdk-headless-1.8.0.131-0.b11.el6_9.i686 --> Processing Dependency: nss >= 3.28.4 for package: 1:java-1.8.0-openjdk-headless-1.8.0.131-0.b11.el6_9.i686 ---> Package xorg-x11-fonts-Type1.noarch 0:7.2-11.el6 will be installed --> Processing Dependency: ttmkfdir for package: xorg-x11-fonts-Type1-7.2-11.el6.noarch --> Processing Dependency: ttmkfdir for package: xorg-x11-fonts-Type1-7.2-11.el6.noarch --> Processing Dependency: mkfontdir for package: xorg-x11-fonts-Type1-7.2-11.el6.noarch --> Processing Dependency: mkfontdir for package: xorg-x11-fonts-Type1-7.2-11.el6.noarch --> Running transaction check ---> Package nss.i686 0:3.15.1-15.el6 will be updated --> Processing Dependency: nss = 3.15.1-15.el6 for package: nss-sysinit-3.15.1-15.el6.i686 --> Processing Dependency: nss(x86-32) = 3.15.1-15.el6 for package: nss-tools-3.15.1-15.el6.i686 ---> Package nss.i686 0:3.28.4-1.el6_9 will be an update --> Processing Dependency: nss-util >= 3.28.3 for package: nss-3.28.4-1.el6_9.i686 --> Processing Dependency: nss-softokn(x86-32) >= 3.14.3-22 for package: nss-3.28.4-1.el6_9.i686 --> Processing Dependency: nspr >= 4.13.0 for package: nss-3.28.4-1.el6_9.i686 --> Processing Dependency: libnssutil3.so(NSSUTIL_3.24) for package: nss-3.28.4-1.el6_9.i686 --> Processing Dependency: libnssutil3.so(NSSUTIL_3.21) for package: nss-3.28.4-1.el6_9.i686 --> Processing Dependency: libnssutil3.so(NSSUTIL_3.17.1) for package: nss-3.28.4-1.el6_9.i686 ---> Package ttmkfdir.i686 0:3.0.9-32.1.el6 will be installed ---> Package tzdata-java.noarch 0:2017b-1.el6 will be installed ---> Package xorg-x11-font-utils.i686 1:7.2-11.el6 will be installed --> Processing Dependency: libfontenc.so.1 for package: 1:xorg-x11-font-utils-7.2-11.el6.i686 --> Processing Dependency: libXfont.so.1 for package: 1:xorg-x11-font-utils-7.2-11.el6.i686 --> Running transaction check ---> Package libXfont.i686 0:1.5.1-2.el6 will be installed ---> Package libfontenc.i686 0:1.1.2-3.el6 will be installed ---> Package nspr.i686 0:4.10.0-1.el6 will be updated ---> Package nspr.i686 0:4.13.1-1.el6 will be an update ---> Package nss-softokn.i686 0:3.14.3-9.el6 will be updated ---> Package nss-softokn.i686 0:3.14.3-23.3.el6_8 will be an update --> Processing Dependency: nss-softokn-freebl(x86-32) >= 3.14.3-23.3.el6_8 for package: nss-softokn-3.14.3-23.3.el6_8.i686 ---> Package nss-sysinit.i686 0:3.15.1-15.el6 will be updated ---> Package nss-sysinit.i686 0:3.28.4-1.el6_9 will be an update ---> Package nss-tools.i686 0:3.15.1-15.el6 will be updated ---> Package nss-tools.i686 0:3.28.4-1.el6_9 will be an update ---> Package nss-util.i686 0:3.15.1-3.el6 will be updated ---> Package nss-util.i686 0:3.28.4-1.el6_9 will be an update --> Running transaction check ---> Package nss-softokn-freebl.i686 0:3.14.3-9.el6 will be updated ---> Package nss-softokn-freebl.i686 0:3.14.3-23.3.el6_8 will be an update --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================ Package Arch Version Repository Size ============================================================================================================ Installing: java-1.8.0-openjdk i686 1:1.8.0.131-0.b11.el6_9 updates 187 k Installing for dependencies: giflib i686 4.1.6-3.1.el6 os 37 k java-1.8.0-openjdk-headless i686 1:1.8.0.131-0.b11.el6_9 updates 31 M libXfont i686 1.5.1-2.el6 os 153 k libfontenc i686 1.1.2-3.el6 os 29 k ttmkfdir i686 3.0.9-32.1.el6 os 41 k tzdata-java noarch 2017b-1.el6 updates 183 k xorg-x11-font-utils i686 1:7.2-11.el6 os 73 k xorg-x11-fonts-Type1 noarch 7.2-11.el6 os 520 k Updating for dependencies: nspr i686 4.13.1-1.el6 os 116 k nss i686 3.28.4-1.el6_9 updates 883 k nss-softokn i686 3.14.3-23.3.el6_8 os 270 k nss-softokn-freebl i686 3.14.3-23.3.el6_8 os 157 k nss-sysinit i686 3.28.4-1.el6_9 updates 51 k nss-tools i686 3.28.4-1.el6_9 updates 453 k nss-util i686 3.28.4-1.el6_9 updates 68 k Transaction Summary ============================================================================================================ Install 9 Package(s) Upgrade 7 Package(s) Total download size: 34 M Downloading Packages: (1/16): giflib-4.1.6-3.1.el6.i686.rpm | 37 kB 00:00 (2/16): java-1.8.0-openjdk-1.8.0.131-0.b11.el6_9.i686.rpm | 187 kB 00:00 (3/16): java-1.8.0-openjdk-headless-1.8.0.131-0.b11.el6_9.i686.rpm | 31 MB 00:01 (4/16): libXfont-1.5.1-2.el6.i686.rpm | 153 kB 00:00 (5/16): libfontenc-1.1.2-3.el6.i686.rpm | 29 kB 00:00 (6/16): nspr-4.13.1-1.el6.i686.rpm | 116 kB 00:00 (7/16): nss-3.28.4-1.el6_9.i686.rpm | 883 kB 00:00 (8/16): nss-softokn-3.14.3-23.3.el6_8.i686.rpm | 270 kB 00:00 (9/16): nss-softokn-freebl-3.14.3-23.3.el6_8.i686.rpm | 157 kB 00:00 (10/16): nss-sysinit-3.28.4-1.el6_9.i686.rpm | 51 kB 00:00 (11/16): nss-tools-3.28.4-1.el6_9.i686.rpm | 453 kB 00:00 (12/16): nss-util-3.28.4-1.el6_9.i686.rpm | 68 kB 00:00 (13/16): ttmkfdir-3.0.9-32.1.el6.i686.rpm | 41 kB 00:00 (14/16): tzdata-java-2017b-1.el6.noarch.rpm | 183 kB 00:00 (15/16): xorg-x11-font-utils-7.2-11.el6.i686.rpm | 73 kB 00:00 (16/16): xorg-x11-fonts-Type1-7.2-11.el6.noarch.rpm | 520 kB 00:00 ------------------------------------------------------------------------------------------------------------ Total 24 MB/s | 34 MB 00:01 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Updating : nspr-4.13.1-1.el6.i686 1/23 Updating : nss-util-3.28.4-1.el6_9.i686 2/23 Updating : nss-softokn-freebl-3.14.3-23.3.el6_8.i686 3/23 Updating : nss-softokn-3.14.3-23.3.el6_8.i686 4/23 Updating : nss-3.28.4-1.el6_9.i686 5/23 Updating : nss-sysinit-3.28.4-1.el6_9.i686 6/23 Installing : libfontenc-1.1.2-3.el6.i686 7/23 Installing : tzdata-java-2017b-1.el6.noarch 8/23 Installing : 1:java-1.8.0-openjdk-headless-1.8.0.131-0.b11.el6_9.i686 9/23 Installing : libXfont-1.5.1-2.el6.i686 10/23 Installing : 1:xorg-x11-font-utils-7.2-11.el6.i686 11/23 Installing : giflib-4.1.6-3.1.el6.i686 12/23 Installing : ttmkfdir-3.0.9-32.1.el6.i686 13/23 Installing : xorg-x11-fonts-Type1-7.2-11.el6.noarch 14/23 Installing : 1:java-1.8.0-openjdk-1.8.0.131-0.b11.el6_9.i686 15/23 Updating : nss-tools-3.28.4-1.el6_9.i686 16/23 Cleanup : nss-tools-3.15.1-15.el6.i686 17/23 Cleanup : nss-3.15.1-15.el6.i686 18/23 Cleanup : nss-sysinit-3.15.1-15.el6.i686 19/23 Cleanup : nss-softokn-3.14.3-9.el6.i686 20/23 Cleanup : nss-util-3.15.1-3.el6.i686 21/23 Cleanup : nspr-4.10.0-1.el6.i686 22/23 Cleanup : nss-softokn-freebl-3.14.3-9.el6.i686 23/23 Verifying : libfontenc-1.1.2-3.el6.i686 1/23 Verifying : nss-sysinit-3.28.4-1.el6_9.i686 2/23 Verifying : nss-3.28.4-1.el6_9.i686 3/23 Verifying : nss-softokn-freebl-3.14.3-23.3.el6_8.i686 4/23 Verifying : tzdata-java-2017b-1.el6.noarch 5/23 Verifying : libXfont-1.5.1-2.el6.i686 6/23 Verifying : nss-tools-3.28.4-1.el6_9.i686 7/23 Verifying : nss-util-3.28.4-1.el6_9.i686 8/23 Verifying : 1:xorg-x11-font-utils-7.2-11.el6.i686 9/23 Verifying : 1:java-1.8.0-openjdk-headless-1.8.0.131-0.b11.el6_9.i686 10/23 Verifying : ttmkfdir-3.0.9-32.1.el6.i686 11/23 Verifying : nss-softokn-3.14.3-23.3.el6_8.i686 12/23 Verifying : nspr-4.13.1-1.el6.i686 13/23 Verifying : giflib-4.1.6-3.1.el6.i686 14/23 Verifying : 1:java-1.8.0-openjdk-1.8.0.131-0.b11.el6_9.i686 15/23 Verifying : xorg-x11-fonts-Type1-7.2-11.el6.noarch 16/23 Verifying : nss-sysinit-3.15.1-15.el6.i686 17/23 Verifying : nss-util-3.15.1-3.el6.i686 18/23 Verifying : nspr-4.10.0-1.el6.i686 19/23 Verifying : nss-softokn-3.14.3-9.el6.i686 20/23 Verifying : nss-softokn-freebl-3.14.3-9.el6.i686 21/23 Verifying : nss-3.15.1-15.el6.i686 22/23 Verifying : nss-tools-3.15.1-15.el6.i686 23/23 Installed: java-1.8.0-openjdk.i686 1:1.8.0.131-0.b11.el6_9 Dependency Installed: giflib.i686 0:4.1.6-3.1.el6 java-1.8.0-openjdk-headless.i686 1:1.8.0.131-0.b11.el6_9 libXfont.i686 0:1.5.1-2.el6 libfontenc.i686 0:1.1.2-3.el6 ttmkfdir.i686 0:3.0.9-32.1.el6 tzdata-java.noarch 0:2017b-1.el6 xorg-x11-font-utils.i686 1:7.2-11.el6 xorg-x11-fonts-Type1.noarch 0:7.2-11.el6 Dependency Updated: nspr.i686 0:4.13.1-1.el6 nss.i686 0:3.28.4-1.el6_9 nss-softokn.i686 0:3.14.3-23.3.el6_8 nss-softokn-freebl.i686 0:3.14.3-23.3.el6_8 nss-sysinit.i686 0:3.28.4-1.el6_9 nss-tools.i686 0:3.28.4-1.el6_9 nss-util.i686 0:3.28.4-1.el6_9 Complete! [root@VM_238_215_centos ~]# java -version openjdk version "1.8.0_131" OpenJDK Runtime Environment (build 1.8.0_131-b11) OpenJDK Server VM (build 25.131-b11, mixed mode)