一、yum命令的基本查询功能

yum有很多子命令,它的基本格式是:

yum SubCommand File_Name | Package_Name

可以使用man来查看一下yum的帮助信息:

 

[root@localhost ~]# man yum

command is one of:

repolist [all|enabled|disabled]:显示当前使用的仓

* list [...]  显示相关程序包,list子命令还有很多选项可用:

yum list [all | glob_exp1] [glob_exp2] [...]显示所有的软件包

yum list available [glob_exp1] [...]可用的软件包

yum list updates [glob_exp1] [...]可升级的软件包

yum list installed [glob_exp1] [...]已经安装的软件包

yum list extras [glob_exp1] [...]当前系统上已安装的,但环境中配置的repository里没有的软件包

yum list obsoletes [glob_exp1] [...]当前系统上已安装的,但环境配置的repository例已经废弃的软件包

yum list recent: 新添加进来的rpm

              

info [...]yum info package_name: 显示软件包的摘要信息,有点类似于rpm -qi命令

clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]: 

本地的缓存可能不能及时更新,需要清空,使用该命令来管理本地缓存

* makecache 清理了缓存后可以手段建立缓存

groupinfo group_name :跟组名相关的信息

groupinstall group1 [group2] [...]: 可以使用yum 来安装一组软件包,即包组 

grouplist [hidden] [groupwildcard] [...]: 查看包组的信息

       

二、yum命令实例演示

/*--------yum list命令演示--------*/

首先使用yum命令结合其list子命令来查看一下仓库里的包的信息

如果只想显示特定的包,list子命令可以通配符使用:

[root@localhost yum.repos.d]# yum list all bind*

# 只想显示bind开头的包
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 
Installed Packages
# 以下是已经安装的包
bind-chroot.x86_64         32:9.8.2-0.17.rc1.el6_4.6          installed                               
bind-libs.x86_6432:9.8.2-0.17.rc1.el6_4.6          @anaconda-CentOS-201311272149.x86_64/6.5
bind-utils.x86_6432:9.8.2-0.17.rc1.el6_4.6          @anaconda-CentOS-201311272149.x86_64/6.5
 
Available Packages
# 以下是可以安装的包
bind.x86_64                    32:9.8.2-0.17.rc1.el6_4.6          base                                    
bind-devel.i686                32:9.8.2-0.17.rc1.el6_4.6          base                                    
bind-devel.x86_64              32:9.8.2-0.17.rc1.el6_4.6          base                                    
bind-dyndb-ldap.x86_64         2.3-5.el6                        base                                    
bind-libs.i686                 32:9.8.2-0.17.rc1.el6_4.6          base                                    
bind-sdb.x86_64                32:9.8.2-0.17.rc1.el6_4.6          base

 

[root@localhost yum.repos.d]# yum list installed bind*

# 使用installed选项查看已安装的bind开头的包
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Installed Packages
bind-chroot.x86_64           32:9.8.2-0.17.rc1.el6_4.6            installed                               
bind-libs.x86_64             32:9.8.2-0.17.rc1.el6_4.6            @anaconda-CentOS-201311272149.x86_64/6.5
bind-utils.x86_64            32:9.8.2-0.17.rc1.el6_4.6            @anaconda-CentOS-201311272149.x86_64/6.5


[root@localhost yum.repos.d]# yum list available bind*

# 使用available选项查看可安装的bind开头的包
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Available Packages
bind.x86_64             32:9.8.2-0.17.rc1.el6_4.6                            base
bind-devel.i686           32:9.8.2-0.17.rc1.el6_4.6                            base
bind-devel.x86_64         32:9.8.2-0.17.rc1.el6_4.6                            base
bind-dyndb-ldap.x86_64      2.3-5.el6                            base
bind-libs.i686                  32:9.8.2-0.17.rc1.el6_4.6                       base
bind-sdb.x86_64          32:9.8.2-0.17.rc1.el6_4.6                            base

 

/*--------yum list命令演示--------*/

 

[root@localhost yum.repos.d]# yum repolist

# 使用yum repolist可以查看当前使用的yum仓库
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
repo id           repo name                      status
base            CentOS 6.4 x86_64                6367
#只有一个仓库,叫做base我们自己定义的描述一共有6367个包
repolist: 6367


 

[root@localhost ~]# yum repolist all

# 加上all选项可以看到所有的yum仓库,包括已被禁用的yum仓库
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
repo id            repo name                status
C6.0-base                               CentOS-6.0 - Base                               disabled
C6.0-centosplus                         CentOS-6.0 - CentOSPlus                         disabled
...
C6.3-updates                            CentOS-6.3 - Updates                            disabled
base                                    CentOS 6.4 x86_64                               enabled: 6,367
repolist: 6,367


 

命令repolist默认显示的是enable的仓库。

 

/*--------yum info命令演示--------*/

使用yum info命令可以获取软件包的摘要信息

[root@localhost ~]# yum info zsh

Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Installed Packages
# 显示了这个软件包是已经安装的还是没有安装的
Name        : zsh
Arch        : x86_64
Version     : 4.3.10
Release     : 7.el6
Size        : 4.8 M
Repo        : installed
Summary     : A powerful interactive shell
URL         : http://zsh.sunsite.dk/
License     : BSD
Description : The zsh shell is a command interpreter usable as an interactive login
            : shell and as a shell script command processor.  Zsh resembles the ksh
            : shell (the Korn shell), but includes many enhancements.  Zsh supports
            : command line editing, built-in spelling correction, programmable
            : command completion, shell functions (with autoloading), a history
            : mechanism, and more.


 

该命令虽然没有rpm -qi命令显示的信息全面,但也提供了很多有用的信息,如该软件包是否已经安装了:

 

[root@localhost ~]# yum info bind

Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Available Packages
# 没有安装的软件包可能会显示为Available Packages
Name        : bind
Arch        : x86_64
Epoch       : 32
Version     : 9.8.2
Release     : 0.17.rc1.el6_4.6
Size        : 4.0 M
Repo        : base
Summary     : The Berkeley Internet Name Domain (BIND) DNS (Domain Name System) server
URL         : http://www.isc.org/products/BIND/
License     : ISC
Description : BIND (Berkeley Internet Name Domain) is an implementation of the DNS
            : (Domain Name System) protocols. BIND includes a DNS server (named),
            : which resolves host names to IP addresses; a resolver library
            : (routines for applications to use when interfacing with DNS); and
            : tools for verifying that the DNS server is operating properly.


之所以能显示没有安装的软件包的相关信息,是因为yum仓库中提供了这些包的信息,可以自动获取。

 

/*--------yum grouplist命令演示获取包组信息--------*/

 

[root@localhost ~]# yum grouplist

Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Group Process
Loading mirror speeds from cached hostfile
Installed Groups:
   Additional Development
   Base
   Debugging Tools
   Desktop
   Desktop Debugging and Performance Tools
...
   Xhosa Support [xh]
   Zulu Support [zu]
Done

 

/*--------yum groupinfo命令演示获取包组的具体包信息--------*/

 

[root@localhost ~]# yum groupinfo "Development tools"

# 注意包名要使用双引号 
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Group Process
Loading mirror speeds from cached hostfile
 
Group: Development tools
 Description: A basic development environment.
 Mandatory Packages: 
# 强制安装的包
   autoconf
   rpm-build
 Default Packages:
# 默认安装的包
   byacc
   cscope  
   Systemtap
 
 Optional Packages:
# 可选安装的包
   ElectricFence
   ant
   systemtap-sdt-devel
   systemtap-server

 

/*--------yum clean命令演示清空缓存--------*/

[root@localhost ~]# yum list 

# 当前的仓库内容
yum-plugin-tsflags.noarch                  1.1.30-14.el6               base                                    
...                                   
zlib-devel.x86_64                          1.2.3-29.el6                base                                    
zlib-static.x86_64                         1.2.3-29.el6                base                                    
zsh-html.x86_64


 

[root@localhost ~]# yum clean all

# 清空缓存
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: base
Cleaning up Everything
Cleaning up list of fastest mirrors

 

完全清空缓存代价较大,建议只清理元数据metadata

[root@localhost ~]# yum clean metadata

Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: base
4 metadata files removed
3 sqlite files removed
0 metadata files removed

 

[root@localhost ~]# yum list

# 更新到最新的list
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors  
base                                    | 4.0 kB     00:00 ... 
base/primary_db           
...
zlib-devel.x86_64                          1.2.3-29.el6                base                                    
zlib-static.x86_64                         1.2.3-29.el6                base                                    
zsh-html.x86_64                            4.3.10-7.el6                base

                       

 /*--------yum makecache命令演示手动建立缓存--------*/

 

[root@localhost ~]# yum clean all

Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: base
Cleaning up Everything
Cleaning up list of fastest mirrors

 

[root@localhost ~]# yum makecache

Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
base                                          | 4.0 kB     00:00 ... 
base/group_gz                                  | 220 kB     00:00 ... 
base/filelists_db                                 | 5.8 MB     00:00 ... 
base/primary_db                                 | 4.4 MB     00:00 ... 
base/other_db                                   | 2.7 MB     00:00 ... 
Metadata Cache Created