Uninstall the JDK that comes with CentOS
1. Review the current JDK version and uninstall
[[email protected] opt]# rpm -qa|grep java java-1.6.0-openjdk-1.6.0.37-1.13.9.4.el5_11tzdata-java-2015g-1.el5//卸载[[email protected] opt]# rpm -e --allmatches --nodeps java-1.6.0-openjdk-1.6.0.37-1.13.9.4.el5_11[[email protected] opt]# rpm -e --allmatches --nodeps tzdata-java-2015g-1.el5
Installing the JDK
1. Find Java-related lists
[[email protected] jre-1.6.0-openjdk.x86_64]# yum -y list java*loaded plugins: fastestmirrorloading mirror speeds from cached hostfile * addons: mirrors.btte.net * base: centos.ustc.edu.cn * extras: Centos.ustc.edu.cn * updates: centos.ustc.edu.cninstalled packagesjava-1.6.0-openjdk.x86_ 64 1:1.6.0.37-1.13.9.4.el5_11 installedAvailable Packagesjava-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-compat-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.x86_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_11 updates java-1.6.0-openjdk-src.x86_64 &Nbsp; 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.x86_64 1:0.10-0.k.6jpp.1 base java_cup-javadoc.x86_64 1:0.10-0.k.6jpp.1 base java_cup-manual.x86_64 1:0.10-0.k.6jpp.1 base javacc.x86_64 4.0-3jpp.3 base javacc-demo.x86_64 4.0-3jpp.3 base javacc-manual.x86_64 4.0-3jpp.3 base
[[Email protected] jre-1.6.0-openjdk.x86_64]# yum search jdkloaded plugins: fastestmirrorloading mirror speeds from cached hostfile * addons: mirrors.btte.net * base: centos.ustc.edu.cn * extras: centos.ustc.edu.cn * updates: centos.ustc.edu.cn========================================================== Matched: jdk ==========================================================java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environmentjava-1.6.0-openjdk-demo.x86_64 : OpenJDK demosjava-1.6.0-openjdk-devel.x86_64 : openjdk development environmentjava-1.6.0-openjdk-javadoc.x86_64 : openjdk api Documentationjava-1.6.0-openjdk-src.x86_64 : openjdk source bundlejava-1.7.0-openjdk.x86_ 64 : openjdk runtime environmentjava-1.7.0-openjdk-demo.x86_64 : openjdk demosjava-1.7.0-openjdk-devel.x86_64 : openjdk development environmentjava-1.7.0-openjdk-javadoc.x86_64 : openjdk api documentationjava-1.7.0-openjdk-src.x86_64 : openjdk source bundlegnu-crypto-sasl-jdk1.4.x86_64 : gnu crypto sasl apijakarta-commons-beanutils.x86_64 : jakarta commons beanutils packagejakarta-commons-collections.x86_64 : jakarta commons collections packagejakarta-commons-launcher.x86_64 : the launcher component is designed to be a cross platform Java application launcher.ldapjdk.x86_64 : the mozilla ldap java sdkldapjdk-javadoc.x86_64 : javadoc for ldapjdkmockobjects-alt-jdk1.4.x86_64 : mockable api for jdk 1.4mockobjects-jdk1.4.x86_64 : mockobjects for 1.4 jdk
2. Installing the JDK
[[email protected] ~]# yum install java-1.6.0-openjdk.x86_64 …… Total download size: 44 MIs this ok [y/N]: y
3. After the installation is complete, verify that
[[email protected] ~]# java -versionjava version "1.6.0_37"OpenJDK Runtime Environment (IcedTea6 1.13.9) (rhel-1.13.9.4.el5_11-x86_64)OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)
4. The path to the default installation via Yum is
/usr/lib/jvm
[[email protected] ~]# cd /usr/lib/jvm[[email protected] jvm]# lltotal 24drwxr-xr-x 3 root root 4096 Jan 12 20:01 java-1.6.0-openjdk-1.6.0.37.x86_64lrwxrwxrwx 1 root root 21 Jan 12 20:01 jre -> /etc/alternatives/jrelrwxrwxrwx 1 root root 27 Jan 12 20:01 jre-1.6.0 -> /etc/alternatives/jre_1.6.0lrwxrwxrwx 1 root root 38 Jan 12 20:01 jre-1.6.0-openjdk.x86_64 -> java-1.6.0-openjdk-1.6.0.37.x86_64/jrelrwxrwxrwx 1 root root 29 Jan 12 20:01 jre-openjdk -> /etc/alternatives/jre_openjdk
If more than one JDK is installed on the machine, the Java command can point to only one version of the JDK, in order to make it easy to modify the JDK version in the global
The/etc/alternatives directory below will have a Java link to the Bin/java command that defaults to the version of the JDK that needs to be executed
[[email protected] jvm]# cd /etc/alternatives[[email protected] alternatives]# lltotal 204lrwxrwxrwx 1 root root 46 Jan 12 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
[[email protected] alternatives]# cd /usr/bin[[email protected] bin]# ll |grep javalrwxrwxrwx 1 root root 22 Jan 12 20:01 java -> /etc/alternatives/java
5. Add the JDK installation path to the Java_home
Method One:
[[email protected] bin]# vi /etc/profile
At the end of the document, add:
#set java environmentJAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk.x86_64PATH=$PATH:$JAVA_HOME/binCLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarexport JAVA_HOME CLASSPATH PATH
Modify/etc/profile to take effect
[[email protected] alternatives]# . /etc/profile
Attention. Then there should be a space
Method Two:
Or install the form of the Java command above to make it easier to modify
[[email protected] jvm]# cd /etc/alternatives[[email protected] alternatives]# ln -s /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/ java_home
Create a/etc/alternatives/java_home soft connection that points the connection to the root of the current JDK
Then add the path to the connection.
#set java environmentJAVA_HOME=/etc/alternatives/java_homePATH=$PATH:$JAVA_HOME/binCLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarexport JAVA_HOME CLASSPATH PATH
[[email protected] alternatives]# export |grep JAVA_HOMEdeclare -x JAVA_HOME="/etc/alternatives/java_home"
Install jdk< on CentOS Linux via yum >