在CentOS linux上通过yum安装JDK<转>

卸载centos自带的jdk

1.查看当前的jdk版本,并卸载

[[email protected] 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
//卸载
[[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

安装Jdk

1.查找java相关得列表

[[email protected] jre-1.6.0-openjdk.x86_64]# yum -y list java*
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.edu.cn
Installed Packages
java-1.6.0-openjdk.x86_64                                        1:1.6.0.37-1.13.9.4.el5_11                              installed
Available Packages
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-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

[[email protected] 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.edu.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 Java application launcher.
ldapjdk.x86_64 : The Mozilla LDAP Java SDK
ldapjdk-javadoc.x86_64 : Javadoc for ldapjdk
mockobjects-alt-jdk1.4.x86_64 : Mockable API for JDK 1.4
mockobjects-jdk1.4.x86_64 : MockObjects for 1.4 JDK

2.安装jdk

[[email protected] ~]# yum install java-1.6.0-openjdk.x86_64
 …… 
Total download size: 44 M
Is this ok [y/N]: y

3.安装完成之后,验证

[[email protected] ~]# java -version
java 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

[[email protected] ~]# cd /usr/lib/jvm
[[email protected] jvm]# ll
total 24
drwxr-xr-x 3 root root 4096 Jan 12 20:01 java-1.6.0-openjdk-1.6.0.37.x86_64
lrwxrwxrwx 1 root root   21 Jan 12 20:01 jre -> /etc/alternatives/jre
lrwxrwxrwx 1 root root   27 Jan 12 20:01 jre-1.6.0 -> /etc/alternatives/jre_1.6.0
lrwxrwxrwx 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/jre
lrwxrwxrwx 1 root root   29 Jan 12 20:01 jre-openjdk -> /etc/alternatives/jre_openjdk

如果机器上同时安装了多个jdk的话,java命令只能指向一个版本的jdk,为了在全局中方便修改jdk版本

/etc/alternatives 的目录下面会有个java链接,指向默认需要执行的版本的jdk的bin/java 命令

[[email protected] jvm]# cd /etc/alternatives
[[email protected] alternatives]# ll
total 204
lrwxrwxrwx 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

[[email protected] alternatives]# cd /usr/bin
[[email protected] bin]# ll |grep java
lrwxrwxrwx 1 root root         22 Jan 12 20:01 java -> /etc/alternatives/java

5.将jdk的安装路径加入到JAVA_HOME

方法一:

[[email protected] bin]# vi /etc/profile

在文件最后加入:

#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

修改/etc/profile之后让其生效

[[email protected] alternatives]# . /etc/profile

注意 . 之后应有一个空格

方法二:

或者是安装上面创建java命令的形式,以方便修改

[[email protected] jvm]# cd /etc/alternatives
[[email protected] alternatives]# ln -s /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/ java_home

创建一个/etc/alternatives/java_home的软连接,将该连接指向到当前Jdk的根目录

然后将改连接的路径加进去

#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
[[email protected] alternatives]# export |grep JAVA_HOME
declare -x JAVA_HOME="/etc/alternatives/java_home"
时间: 2024-10-28 04:50:20

在CentOS linux上通过yum安装JDK<转>的相关文章

在linux上通过yum安装JDK

卸载centos自带的jdk 1.查看当前的jdk版本,并卸载 [email protected] 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 //卸载 [[email protected] opt]# rpm -e --allmatches --nodeps java-1.6.0-openjdk-1.6.0.37-1.13.9.4.el5_11 [[ema

在linux上使用yum安装JDK

1.查找java相关得列表 [[email protected] ~]$ yum -y list java* 执行结果 [[email protected] ~]$ yum -y list java* Loaded plugins: fastestmirror base | 1.1 kB 00:00 base/primary | 995 kB 00:00 base 2789/2789 extras | 2.1 kB 00:00 extras/primary_db | 164 kB 00:20 u

如何在CentOS 6上通过YUM安装Nginx和PHP-FPM(转)

准备篇: 1.配置防火墙,开启80端口.3306端口       vi /etc/sysconfig/iptables       -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT(允许80端口通过防火墙)       -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT(允许3306端口通过防火墙)特别提示:很多网友把这两条规则添加到防

学习 Mysql - 在linux上使用yum安装MySQL

1.检查已经安装的mysql信息 yum list installed mysql*rpm -qa | grep mysql* 2.列出已安装和可安装的mysql信息 yum list mysql* 3.安装客户端 yum install mysql 4.安装服务器端 yum install mysql-server yum install mysql-devel 5.数据库字符集设置 mysql配置文件/etc/my.cnf中加入default-character-set=utf8 可以使用如

centOS Linux下用yum安装mysql

第一篇:安装和配置MySQL 第一步:安装MySQL [[email protected] local]# yum -y install mysql-server ← 安装MySQL [[email protected] local]# yum -y install php-mysql   ← 安装php-mysql 第二步:配置MySQL [[email protected] local] #vim /etc/my.cnf            ← 编辑MySQL的配置文件 [mysqld]

linux下使用yum安装mysql、tomcat、httpd

一.linux下使用yum安装mysql 1.安装 查看有没有安装过: yum list installed mysql* rpm -qa | grep mysql* 查看有没有安装包: yum list mysql* 安装mysql客户端: yum install mysql 安装mysql 服务器端: yum install mysql-server yum install mysql-devel www.2cto.com 2.启动&&停止 数据库字符集设置 mysql配置文件/etc

centos yum 安装jdk后配置JAVA_HOME

centos6.4 yum 安装jdk和JAVA_HOME的设置 2014-06-17 16:13 1176人阅读 评论(0) 收藏 举报  分类: linux(3)  版权声明:本文为博主原创文章,未经博主允许不得转载. #yum search jdk 查找可用的安装的jdk包 查询结果有以下两项(较新的版本): Java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment java-1.7.0-openjdk-devel.x86_64 : O

在 CentOS/RHEL 7.1, 6.7 and 5.11 版本上用yum安装 PHP 5.4

在 CentOS/RHEL 7.1, 6.7 and 5.11 版本上用yum安装 ?PHP 5.4 在CentOS 7下(包含安装EPEL) wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-7.noarch.rpm wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm rpm -Uvh remi-release-7*.rpm epe

在CentOS 7上使用Yum源安装 Zabbix 3.2

在CentOS 7上使用Yum源安装 Zabbix 3.2 1. 环境准备 [[email protected] ~]# setenforce 0 [[email protected] ~]# sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config [[email protected] ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 [[emai