在Linux中利用yum安装JDK的实现步骤
一、卸载centos自带的jdk
1.查看当前的jdk版本,并卸载
root@localhostopt]#rpm-qa|grepjava java-1.6.0-openjdk-1.6.0.37-1.13.9.4.el5_11 tzdata-java-2015g-1.el5 //卸载 [root@localhostopt]#rpm-e--allmatches--nodepsjava-1.6.0-openjdk-1.6.0.37-1.13.9.4.el5_11 [root@localhostopt]#rpm-e--allmatches--nodepstzdata-java-2015g-1.el5
二、安装Jdk
1.查找java相关得列表
[root@localhostjre-1.6.0-openjdk.x86_64]#yum-ylistjava* Loadedplugins:fastestmirror Loadingmirrorspeedsfromcachedhostfile *addons:mirrors.btte.net *base:centos.ustc.edu.cn *extras:centos.ustc.edu.cn *updates:centos.ustc.edu.cn InstalledPackages java-1.6.0-openjdk.x86_641:1.6.0.37-1.13.9.4.el5_11installed AvailablePackages java-1.4.2-gcj-compat.x86_641.4.2.0-40jpp.115base java-1.4.2-gcj-compat-devel.i3861.4.2.0-40jpp.115base java-1.4.2-gcj-compat-devel.x86_641.4.2.0-40jpp.115base java-1.4.2-gcj-compat-javadoc.x86_641.4.2.0-40jpp.115base java-1.4.2-gcj-compat-src.x86_641.4.2.0-40jpp.115base java-1.6.0-openjdk-demo.x86_641:1.6.0.37-1.13.9.4.el5_11updates java-1.6.0-openjdk-devel.x86_641:1.6.0.37-1.13.9.4.el5_11updates java-1.6.0-openjdk-javadoc.x86_641:1.6.0.37-1.13.9.4.el5_11updates java-1.6.0-openjdk-src.x86_641:1.6.0.37-1.13.9.4.el5_11updates java-1.7.0-openjdk.x86_641:1.7.0.91-2.6.2.1.el5_11updates java-1.7.0-openjdk-demo.x86_641:1.7.0.91-2.6.2.1.el5_11updates java-1.7.0-openjdk-devel.x86_641:1.7.0.91-2.6.2.1.el5_11updates java-1.7.0-openjdk-javadoc.x86_641:1.7.0.91-2.6.2.1.el5_11updates java-1.7.0-openjdk-src.x86_641:1.7.0.91-2.6.2.1.el5_11updates java_cup.x86_641:0.10-0.k.6jpp.1base java_cup-javadoc.x86_641:0.10-0.k.6jpp.1base java_cup-manual.x86_641:0.10-0.k.6jpp.1base javacc.x86_644.0-3jpp.3base javacc-demo.x86_644.0-3jpp.3base javacc-manual.x86_644.0-3jpp.3base
或
[root@localhostjre-1.6.0-openjdk.x86_64]#yumsearchjdk Loadedplugins:fastestmirror Loadingmirrorspeedsfromcachedhostfile *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:OpenJDKRuntimeEnvironment java-1.6.0-openjdk-demo.x86_64:OpenJDKDemos java-1.6.0-openjdk-devel.x86_64:OpenJDKDevelopmentEnvironment java-1.6.0-openjdk-javadoc.x86_64:OpenJDKAPIDocumentation java-1.6.0-openjdk-src.x86_64:OpenJDKSourceBundle java-1.7.0-openjdk.x86_64:OpenJDKRuntimeEnvironment java-1.7.0-openjdk-demo.x86_64:OpenJDKDemos java-1.7.0-openjdk-devel.x86_64:OpenJDKDevelopmentEnvironment java-1.7.0-openjdk-javadoc.x86_64:OpenJDKAPIDocumentation java-1.7.0-openjdk-src.x86_64:OpenJDKSourceBundle gnu-crypto-sasl-jdk1.4.x86_64:GnuCryptoSASLAPI jakarta-commons-beanutils.x86_64:JakartaCommonsBeanUtilsPackage jakarta-commons-collections.x86_64:JakartaCommonsCollectionsPackage jakarta-commons-launcher.x86_64:TheLauncherComponentisdesignedtobeacrossplatformJavaapplicationlauncher. ldapjdk.x86_64:TheMozillaLDAPJavaSDK ldapjdk-javadoc.x86_64:Javadocforldapjdk mockobjects-alt-jdk1.4.x86_64:MockableAPIforJDK1.4 mockobjects-jdk1.4.x86_64:MockObjectsfor1.4JDK
2.安装jdk
[root@localhost~]#yuminstalljava-1.6.0-openjdk.x86_64 …… Totaldownloadsize:44M Isthisok[y/N]:y
3.安装完成之后,验证
[root@localhost~]#java-version javaversion"1.6.0_37" OpenJDKRuntimeEnvironment(IcedTea61.13.9)(rhel-1.13.9.4.el5_11-x86_64) OpenJDK64-BitServerVM(build23.25-b01,mixedmode)
4.通过yum默认安装的路径为
/usr/lib/jvm
[root@localhost~]#cd/usr/lib/jvm [root@localhostjvm]#ll total24 drwxr-xr-x3rootroot4096Jan1220:01java-1.6.0-openjdk-1.6.0.37.x86_64 lrwxrwxrwx1rootroot21Jan1220:01jre->/etc/alternatives/jre lrwxrwxrwx1rootroot27Jan1220:01jre-1.6.0->/etc/alternatives/jre_1.6.0 lrwxrwxrwx1rootroot38Jan1220:01jre-1.6.0-openjdk.x86_64->java-1.6.0-openjdk-1.6.0.37.x86_64/jre lrwxrwxrwx1rootroot29Jan1220:01jre-openjdk->/etc/alternatives/jre_openjdk
如果机器上同时安装了多个jdk的话,java命令只能指向一个版本的jdk,为了在全局中方便修改jdk版本
/etc/alternatives的目录下面会有个java链接,指向默认需要执行的版本的jdk的bin/java命令
[root@localhostjvm]#cd/etc/alternatives [root@localhostalternatives]#ll total204 lrwxrwxrwx1rootroot46Jan1220:01java->/usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
而/etc/alternatives/java又会被软连接到/usr/bin/java
5.将jdk的安装路径加入到JAVA_HOME
方法一:
[root@localhostbin]#vi/etc/profile
在文件最后加入:
#setjavaenvironment 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 exportJAVA_HOMECLASSPATHPATH
修改/etc/profile之后让其生效
[root@localhostalternatives]#./etc/profile
注意.之后应有一个空格
方法二:
或者是安装上面创建java命令的形式,以方便修改
[root@localhostjvm]#cd/etc/alternatives [root@localhostalternatives]#ln-s/usr/lib/jvm/jre-1.6.0-openjdk.x86_64/java_home
创建一个/etc/alternatives/java_home的软连接,将该连接指向到当前Jdk的根目录
然后将改连接的路径加进去
#setjavaenvironment JAVA_HOME=/etc/alternatives/java_home PATH=$PATH:$JAVA_HOME/bin CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar exportJAVA_HOMECLASSPATHPATH
[root@localhostalternatives]#export|grepJAVA_HOME declare-xJAVA_HOME="/etc/alternatives/java_home"
总结
以上就是这篇文章的全部内容,希望大家能够喜欢。