First, uninstall CentOS self-with JDK
1. View the current JDK version and uninstall
Root@localhost opt]# rpm-qa|grep java
java-1.6.0-openjdk-1.6.0.37-1.13.9.4.el5_11
Tzdata-java-2015g-1.el5
//Uninstall
[Root@localhost opt]# rpm-e--allmatches--nodeps java-1.6.0-openjdk-1.6.0.37-1.13.9.4.el5_11
[root@localhost opt]# rpm-e--allmatches--nodeps tzdata-java-2015g-1.el5
Second, the installation of JDK
1. Find Java Related list
[root@localhost jre-1.6.0-openjdk.x86_64]# yum-y list java* Loaded plugins:fastestmirror Loading mirror speeds from CAC Hed hostfile * addons:mirrors.btte.net * base:centos.ustc.edu.cn * extras:centos.ustc.edu.cn * UPDATES:CENTOS.USTC . edu.cn installed Packages java-1.6.0-openjdk.x86_64 1:1.6.0.37-1.13.9.4.el5_11 installed Available Packag Es java-1.4.2-gcj-compat.x86_64 1.4.2.0-40jpp.115 base java-1.4.2-gcj-compat-devel.i386 1.4.2. 0-40jpp.115 base java-1.4.2-gcj-compat-devel.x86_64 1.4.2.0-40jpp.115 base java-1.4.2-gcj-com pat-javadoc.x86_64 1.4.2.0-40jpp.115 Base java-1.4.2-gcj-compat-src.x86_64 1.4.2.0-40jpp.115 Base java-1.6.0-openjdk-demo.x86_64 1:1.6.0.37-1.13.9.4.el5_11 Updates java-1.6.0-openjdk-devel.x8 6_64 1:1.6.0.37-1.13.9.4.el5_11 Updates java-1.6.0-openjdk-javadoc.x86_64 1:1.6.0.37-1.13.9.4.el5_1 1 Updates Java-1.6.0-openjdk-src.x86_64 1:1.6.0.37-1.13.9.4.el5_11 Updates java-1.7.0-openjdk.x86_64 1:1.7.0.91-2 .6.2.1.el5_11 updates java-1.7.0-openjdk-demo.x86_64 1:1.7.0.91-2.6.2.1.el5_11 updates java-1.7.0- openjdk-devel.x86_64 1:1.7.0.91-2.6.2.1.el5_11 Updates java-1.7.0-openjdk-javadoc.x86_64 1:1.7.0.91 -2.6.2.1.el5_11 updates java-1.7.0-openjdk-src.x86_64 1:1.7.0.91-2.6.2.1.el5_11 updates java_cup.x 86_64 1:0.10-0.K.6JPP.1 base java_cup-javadoc.x86_64 1:0.10-0.k.6jpp.1 base Ja va_cup-manual.x86_64 1:0.10-0.K.6JPP.1 base javacc.x86_64 4.0-3jpp.3 base Ja vacc-demo.x86_64 4.0-3JPP.3 base javacc-manual.x86_64 4.0-3JPP.3 Base
or
[Root@localhost jre-1.6.0-openjdk.x86_64]# Yum search jdk Loaded plugins:fastestmirror Loading mirror speeds from cached Hostfile * addons:mirrors.btte.net * base:centos.ustc.edu.cn * extras:centos.ustc.edu.cn * Updates:centos.ustc.ed u.cn ========================================================== matched:jdk ===================================== ===================== JAVA-1.6.0-OPENJDK.X86_64:OPENJDK Runtime Environment JAVA-1.6.0-OPENJDK-DEMO.X86_64:OPENJDK Demos java-1.6.0-openjdk-devel.x86_64:openjdk Development Environment JAVA-1.6.0-OPENJDK-JAVADOC.X86_64:OPENJDK API Documentation Java-1.6.0-openjdk-src.x86_64:openjdk Source Bundle JAVA-1.7.0-OPENJDK.X86_64:OPENJDK Runtime Environment JAVA-1.7.0-OPENJDK-DEMO.X86_64:OPENJDK Demos JAVA-1.7.0-OPENJDK-DEVEL.X86_64:OPENJDK Development Environment JAVA-1.7.0-OPENJDK-JAVADOC.X86_64:OPENJDK API Documentation JAVA-1.7.0-OPENJDK-SRC.X86_64:OPENJDK Source Bundle Gnu-crypto-sasl-jdk1.4.x86_64:gnu Crypto SASL API Jakarta-commons-beanutils.x86_64:jakarta Commons beanutils Package Jakarta-commons-collections.x86_64:jakarta Commons Collections Package jakarta-commons-launcher.x86_64:the Launcher Component is designed to be a cross platform Ja
VA Application Launcher. Ldapjdk.x86_64:The Mozilla LDAP Java SDK ldapjdk-javadoc.x86_64:javadoc for LDAPJDK Mockobjects-alt-jdk1.4.x86_64:mo Ckable API for JDK 1.4 mockobjects-jdk1.4.x86_64:mockobjects for 1.4 jdk
2. Install JDK
[Root@localhost ~]# yum install java-1.6.0-openjdk.x86_64 ...
Total download size:44 M are this
OK [y/n]: Y
3. After the installation is complete, verify
[Root@localhost ~]# java-version
java Version "1.6.0_37"
OpenJDK Runtime (Environment IcedTea6) ( rhel-1.13.9.4.el5_11-x86_64)
OpenJDK 64-bit Server VM (build 23.25-b01, Mixed mode)
4. The default installation path via Yum is
/usr/lib/jvm
[Root@localhost ~]# CD/USR/LIB/JVM
[root@localhost jvm]# ll Total
drwxr-xr-x 3 root 4096 12 20:01 Java-1.6.0-openjdk-1.6.0.37.x86_64
lrwxrwxrwx 1 root 20:01 jre->/etc/alternatives/jre lrwxrw
xrwx 1 root 20:01 jre-1.6.0->/etc/alternatives/jre_1.6.0
lrwxrwxrwx 1 root root in 20:01 Jr e-1.6.0-openjdk.x86_64-> Java-1.6.0-openjdk-1.6.0.37.x86_64/jre
lrwxrwxrwx 1 root 12 20:01 JRE-OPENJDK->/ETC/ALTERNATIVES/JRE_OPENJDK
If more than one JDK is installed on the machine, the Java command can only point to one version of the JDK, in order to make it easy to modify the JDK version in the global
/etc/alternatives
The directory below will have a Java link to the command for the JDK that needs to be executed by default bin/java
[Root@localhost jvm]# cd/etc/alternatives
[root@localhost alternatives]# ll Total
204
lrwxrwxrwx 1 Root root 20:01 java->/usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
And /etc/alternatives/java
will be soft connected to/usr/bin/java
5. Add JDK installation path to Java_home
Method One:
[Root@localhost bin]# Vi/etc/profile
At the end of the document add:
#set Java Environment
java_home=/usr/lib/jvm/jre-1.6.0-openjdk.x86_64
path= $PATH: $JAVA _home/bin
Classpath=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar
export java_home CLASSPATH PATH
Modify the/etc/profile to take effect
[Root@localhost alternatives]#. /etc/profile
Attention. There should be a space after
Method Two:
Or install the form above to create Java commands to facilitate modification
[Root@localhost jvm]# cd/etc/alternatives
[root@localhost alternatives]# ln-s Jre-1.6.0-openjdk.x86_64/java_home
Creates a /etc/alternatives/java_home
soft connection that points to the root directory of the current JDK
Then add the path to the connection.
#set Java Environment
java_home=/etc/alternatives/java_home
path= $PATH: $JAVA _home/bin
classpath=.:$ Java_home/lib/dt.jar: $JAVA _home/lib/tools.jar
export java_home CLASSPATH PATH
[root@localhost alternatives]# export |grep java_home
declare-x java_home= "/etc/alternatives/java_home"
Summarize
The above is the entire content of this article, I hope you can enjoy.