前面在说到rpm安装程序时就说过它有一个缺陷,不能解决程序间的依赖关系,而yum能在安装过程中自动解决依赖关系,安装非常方便。
那么什么是yum呢?
yum是基于C/S架构,需要一个服务器端给我们提供各个程序包以及他们之间的依赖关系,当客户端从服务器端下载安装程序时,服务器端会查找元数据信息,包括包的依赖关系,会把依赖的包一起下载到客户端安装。
所以我们需要一个指向这个服务器的配置文件,配置文件在/etc/yum.repos.d/目录下以.repo结尾的配置文件。
该配置文件的格式如下:
[repo-id] :只是一个标识
name :名称
baseurl : 这项很重要,表示程序包的所在路径,注意是在元数据的父目录
enabled :表示是否启动该配置文件,为1时表示启动
gpgcheck :用来校验程序包来源的合法性和完整性,为1时表示启用校验功能
gpgkey :你要下载站点的秘钥,通过这个秘钥能验证程序包合法性
注意:由于该目录下有几个同样以.repo结尾的文件,所以先把其他文件的后缀改变一下
以我自己配置的文件为例,我把所有的.rpm文件都放到/mnt/cdrom目录下
vim /etc/yum.repos.d/yum.repo [cdrom] name=iso baseurl=file:///mnt/cdrom enabled=1 gpgcheck=0
yum命令的可用选项:
-y: 安装过程中自动回答为“yes”
--disablerepo=:临时禁用在配置文件中配置并启用的某repository;
--enablerepo=:临时启用指定的某repo;
--nogpgcheck:禁止做包校验;
仓库管理:
repolist [all|enabled|disabled]
列出当前的repo-id,可以是所有的,启用的或没启用的 [root@localhost yum.repos.d]# yum repolist Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile repo id repo name status cdrom iso 4,184 repolist: 4,184
缓存管理:
clean [ packages | metadata | expire-cache | rpmdb | plugins | all
清除缓存
makecache:缓存创建 自动连接至每一个可用仓库,下载其元数据,将其创建为缓存
程序包查看:
list [all | glob_exp1] [glob_exp2] [...]
list {available|updates|installed|extras|obsoletes}
列出当前的rpm二进制包,支持通配符选项
grouplist 以包组形式列出
程序包安装:
install -y package1 [package2] [...]
[root@localhost yum.repos.d]# yum -y install httpd Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.2.15-39.el6.centos will be installed --> Finished Dependency Resolution Dependencies Resolved =============================================================================================================== Package Arch Version Repository Size =============================================================================================================== Installing: httpd x86_64 2.2.15-39.el6.centos cdrom 825 k Transaction Summary =============================================================================================================== Install 1 Package(s) Total download size: 825 k Installed size: 2.9 M Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Warning: RPMDB altered outside of yum. ** Found 2 pre-existing rpmdb problem(s), ‘yum check‘ output follows: gnome-user-share-2.28.2-3.el6.x86_64 has missing requires of httpd >= (‘0‘, ‘2.2.0‘, None) php-5.3.3-38.el6.x86_64 has missing requires of httpd-mmn = (‘0‘, ‘20051115‘, None) Installing : httpd-2.2.15-39.el6.centos.x86_64 1/1 Verifying : httpd-2.2.15-39.el6.centos.x86_64 1/1 Installed: httpd.x86_64 0:2.2.15-39.el6.centos Complete!
重新安装(覆盖安装)
reinstall package1 [package2] [...]
程序包升级:
update [package1] [package2] [...]
程序包降级:
downgrade package1 [package2] [...]
检查有哪些升级可用:
check-update
卸载:
remove| erase package1 [package2] [...]
所有依赖于正卸载的程序包的程序包会被一并卸载;
查询:
查询程序的相关简要信息:info PACKAGE ...
在包名和sumary信息中搜索指定的关键字:search KEYWORD ...
[root@localhost yum.repos.d]# yum search httpd Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile ============================================= N/S Matched: httpd ============================================== libmicrohttpd-devel.i686 : Development files for libmicrohttpd libmicrohttpd-devel.x86_64 : Development files for libmicrohttpd libmicrohttpd-doc.noarch : Documentation for libmicrohttpd httpd.x86_64 : Apache HTTP Server httpd-devel.i686 : Development interfaces for the Apache HTTP server httpd-devel.x86_64 : Development interfaces for the Apache HTTP server httpd-manual.noarch : Documentation for the Apache HTTP server httpd-tools.x86_64 : Tools for use with the Apache HTTP Server libmicrohttpd.i686 : Lightweight library for embedding a webserver in applications libmicrohttpd.x86_64 : Lightweight library for embedding a webserver in applications mod_auth_mellon.x86_64 : A SAML 2.0 authentication module for the Apache Httpd Server mod_dav_svn.x86_64 : Apache httpd module for Subversion server mod_dnssd.x86_64 : An Apache HTTPD module which adds Zeroconf support
查询指定文件由哪个程序包安装生成:provides|whatprovides /PATH/TO/SOMEFILE
[root@localhost yum.repos.d]# yum provides /bin/ls Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile coreutils-8.4-37.el6.x86_64 : A set of basic GNU tools commonly used in shell scripts Repo : cdrom Matched from: Filename : /bin/ls coreutils-8.4-37.el6.x86_64 : A set of basic GNU tools commonly used in shell scripts Repo : installed Matched from: Other : Provides-match: /bin/ls
包组管理:
列出所有包组:grouplist
显示指定包组详情:groupinfo group1 [...]
安装:groupinstall group1 [group2] [...]
卸载:groupremove group1 [group2] [...]
升级:groupupdate group1 [group2] [...]
Note:可直接用install、remove或update来管理包组:
@GROUP_NAME
例如:yum install @"Server Platform Development"
原文地址:http://zcs1615.blog.51cto.com/8663731/1633064