首页 > 代码库 > 在linux上通过yum安装JDK
在linux上通过yum安装JDK
卸载centos自带的jdk
1.查看当前的jdk版本,并卸载
root@localhost opt]# rpm -qa|grep java java-1.6.0-openjdk-1.6.0.37-1.13.9.4.el5_11tzdata-java-2015g-1.el5//卸载[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
安装Jdk
1.查找java相关得列表
[root@localhost 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 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
或
[root@localhost 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.安装jdk
[root@localhost ~]# yum install java-1.6.0-openjdk.x86_64 …… Total download size: 44 MIs this ok [y/N]: y
3.安装完成之后,验证
[root@localhost ~]# 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.通过yum默认安装的路径为
/usr/lib/jvm
[root@localhost ~]# cd /usr/lib/jvm[root@localhost 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
如果机器上同时安装了多个jdk的话,java命令只能指向一个版本的jdk,为了在全局中方便修改jdk版本
/etc/alternatives 的目录下面会有个java链接,指向默认需要执行的版本的jdk的bin/java 命令
[root@localhost jvm]# cd /etc/alternatives[root@localhost alternatives]# lltotal 204lrwxrwxrwx 1 root root 46 Jan 12 20:01 java -> /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
而/etc/alternatives/java又会被软连接到/usr/bin/java
5.将jdk的安装路径加入到JAVA_HOME
方法一:
[root@localhost bin]# vi /etc/profile
在文件最后加入:
#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
修改/etc/profile之后让其生效
[root@localhost alternatives]# . /etc/profile
注意 . 之后应有一个空格
方法二:
或者是安装上面创建java命令的形式,以方便修改
[root@localhost jvm]# cd /etc/alternatives[root@localhost alternatives]# ln -s /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/ java_home
创建一个/etc/alternatives/java_home的软连接,将该连接指向到当前Jdk的根目录
然后将改连接的路径加进去
#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
[root@localhost alternatives]# export |grep JAVA_HOMEdeclare -x JAVA_HOME="/etc/alternatives/java_home"
专注技术细节,提升自我能力。
--------end------------
在linux上通过yum安装JDK
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。