yum 命令详解

来源:互联网 发布:孙悦cba生涯数据 编辑:程序博客网 时间:2024/05/21 18:45

一、安装YUM工具包

1、删除redhat原有的yum源# rpm -aq | grep yum|xargs rpm -e --nodeps

2、下载新的yum安装包 

这里我们使用CentOS的yum源

#wget http://centos.ustc.edu.cn/centos/5/os/i386/CentOS/yum-3.2.22-40.el5.centos.noarch.rpm
#wget http://centos.ustc.edu.cn/centos/5/os/i386/CentOS/yum-fastestmirror-1.1.16-21.el5.centos.noarch.rpm
#wget http://centos.ustc.edu.cn/centos/5/os/i386/CentOS/yum-metadata-parser-1.1.2-4.el5.i386.rpm

有些包的版本号可能已经改变,如果下载不了,直接上网站查找rpm列表。 

3. 下载并导入KEY
# cd /etc/pki/rpm-gpg/
# wget http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5
# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*

3、安装yum软件包# rpm -ivh python-iniparse-0.3.1-2.1.el6.noarch.rpm 
# rpm -ivh yum-metadata-parser-1.1.2-14.1.el6.i686.rpm 
# rpm -ivh yum-3.2.27-14.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.26-11.el6.noarch.rpm

注意:最后两个安装包要放在一起同时安装,否则会提示相互依赖,安装失败。


rpm -ivh yum-3.2.22-33.el5.centos.noarch.rpm \
 yum-fastestmirror-1.1.16-14.el5.centos.1.noarch.rpm \
 yum-metadata-parser-1.1.2-3.el5.centos.i386.rpm


4、更改yum源  #我们使用网易的CentOS镜像源# cd /etc/yum.repos.d/ 
# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo 


5. 修改配置文件

Vi /etc/yum.repos.d/rhel-debuginfo.repo

[base]
name=Red Hat Enterprise Linux $releasever -Base
baseurl=http://mirrors.sohu.com/centos/5.5/os/$basearch/
gpgcheck=1

[update]
name=Red Hat Enterprise Linux $releasever -Updates
baseurl=http://mirrors.sohu.com/centos/5.5/updates/$basearch/
gpgcheck=1

[extras]
name=Red Hat Enterprise Linux $releasever -Extras
baseurl=http://mirrors.sohu.com/centos/5.5/extras/$basearch/
gpgcheck=1

[addons]
name=Red Hat Enterprise Linux $releasever -Addons
baseurl=http://mirrors.sohu.com/centos/5.5/addons/$basearch/
gpgcheck=1

至此yum安装完成,可以 yum install 安装程序了


二、使用

1、安装、卸载、升级

A、安装

安装一个软件时:yum -y install httpd
安装多个相类似的软件时:yum -y install httpd*
安装多个非类似软件时:yum -y install httpd php php-gd mysql
B、卸载
卸载一个软件时:yum -y remove httpd
卸载多个相类似的软件时:yum -y remove httpd*
卸载多个非类似软件时:yum -y remove httpd php php-gd mysql
C、升级
升级软件:yum -y update firefox

(-y 代表要不要出现安装提示)

2、查询

A、假如你要使用iostat命令,却发现系统没有这个命令

此时,你可以 yum search iostat

[root@localhost ~]# yum search iostat
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: centos.ustc.edu.cn
 * updates: mirrors.163.com
=============================== Matched: iostat ================================
dstat.noarch : Versatile resource statistics tool
sysstat.x86_64 : sar 和 iostat 系统监视命令。

然后你就可以找到和iostat相关的安装包了

B、查询软件信息:yum info sysstat

如果Repo : freshrpms是这样的,表示您的系统没有安装这个软件,如果显示的是:Repo : installed,表示已经安装了。

C、列出已经安装的包:yum list installed 

       列出符合条件的包:yum list mp* |more

       列出某个软件包:yum list firefox

查找某个包是否已安装:yum list installed | grep logwatch

        统计已经安装包数量:yum list installed |wc -l

        统计所有可安装包数量:yum list |wc l

D、查询yum安装日志:tail /var/log/yum.log

       查看yum使用的历史记录的方法:yum history info




==============================================================================================

List of Commands:

install:Install package or packages on your system

update:Update package or packages on your system

remove:移出某个软件,后跟软件名称

search:Search package details for the given string 搜索某个软件或重要关键字

list:List package or groups of packages列出yum所管理的软件名称与版本,www.linuxidc.com类似于rpm –qa

info:Display details about package or group of packages,类似于rpm –qai

clean:Remove cached data 下载文件被放置在/var/cache/yum中,可以使用clean清除。

check-update:Check for available package updates

Groupinfo:Display details about package group

groupinstall   Install the packages in group on your system

grouplist:List available package groups

groupremove:Remove the packages in group from your system

groupupdate:升级整个软件群组

help:Display helpful usage message

Deplist:List package's dependencies    列出软件包的依赖关系,在使用本地源软件包进行安装时,可以查看依赖关系

Downgrade:downgrade package

Erase:Remove package or packages from your system

localinstall:Install local RPM安装本地的rpm软件包

makecache:Generate the metadata cache 生成数据缓存

provides:Find what package provides the given value 找到包提供的给定值

reinstall:reinstall package 重装软件包

repolist:Display the configured software repositories

resolvedep:Determine which package provides the given dependency

shell:Run an interactive yum shell

upgrade:Update packages taking obsoletes into account