系统版本:
[root@centos71d1 ~]# cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)
[root@centos71d1 ~]# uname -r
3.10.0-229.el7.x86_64
yum repository:
存储了众多rpm包,以及包相关的元数据文件(放置于特定目录下:repodata)
yum客户端配置文件:
/etc/yum.conf
: 为所有repo提供公共配置
/etc/yum.repos.d/*.repo
: 为repo的指向提供配置
yum客户端repo配置文件指向的定义:
[repositoryID]
name=name for this repository
baseurl=url://path/to/repository/
enabled={1|0}
gpgcheck={1|0}
gpgkey=URL
enablegroups={1|0}
failovermethod={roundrobin|priority}
#roundrobin: 默认值,意为随机挑选
#priority: 优先级,即从上往下,第一个优先级最高
cost=#
#默认为1000
yum客户端repo配置文件中的可用变量:
$releasever
: 当前OS的发行版的主版本号,如CentOS 6或7$arch
: 平台,如i386或x86_64$basearch
: 基础平台,386、486、586、686的基础平台都是386$YUM0
–$YUM9
: 自定义变量
yum命令语法:
yum [options] [command] [package …]
[options]
- --nogpgcheck: 禁用gpg check
- -y: 自动回答“yes”
- -q: 静默模式
- --disablerepo=repoidglob: 临时禁用此处指定的repo
- --enablerepo=repoidglob: 临时启用此处指定的repo
- --noplugins: 禁用所有插件
[command]
- install package1 [package2] […]
- update [package1] [package2] […]
- update-to [package1] [package2] […]
- check-update
- upgrade [package1] [package2] […]
- upgrade-to [package1] [package2] […]
- distribution-synchronization [package1] [package2] […]
- remove | erase package1 [package2] […]
- list […]
- info […]
- provides | whatprovides feature1 [feature2] […]
- clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]
- makecache
- groupinstall group1 [group2] […]
- groupupdate group1 [group2] […]
- grouplist [hidden] [groupwildcard] […]
- groupremove group1 [group2] […]
- groupinfo group1 […]
- search string1 [string2] […]
- shell [filename]
- resolvedep dep1 [dep2] […]
- localinstall rpmfile1 [rpmfile2] […]
- localupdate rpmfile1 [rpmfile2] […]
- reinstall package1 [package2] […]
- downgrade package1 [package2] […]
- deplist package1 [package2] […]
- repolist [all|enabled|disabled]
- version [ all | installed | available | group-* | nogroups* | grouplist | groupinfo ]
- history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats]
- check
- help [command]
显示仓库列表:
yum repolist [all|enabled|disabled]
示例:
[root@centos71d1 ~]# yum repolist all
repo id repo name status
C7.0.1406-base/x86_64 CentOS-7.0.1406 - Base disabled
!base/7/x86_64 CentOS-7 - Base enabled: 9,911
....
#显示禁用的和启用的软件仓库
显示程序包:
yum list [all | glob_exp1] [glob_exp2] […]
yum list {available|installed|updates} [glob_exp1] […]
示例:
[root@centos71d1 ~]# yum list | less
bash.x86_64 4.2.46-12.el7 @anaconda
bash-completion.noarch 1:2.1-6.el7 @base
bash-completion-extras.noarch 1:2.1-11.el7 @epel
....
#显示程序包,@anaconda表示安装系统时,就已安装好
[root@centos71d1 ~]# yum list installed bash
#显示名称中含有bash字符串的已安装的程序包
[root@centos71d1 ~]# yum list updates xz
#显示已安装的程序包中,名称含有xz的更新包
安装程序包:
yum install package1 [package2] […]
yum reinstall package1 [package2] […]
“yum reinstall”类似于“rpm -ivh --replacepkgs”,表示重新安装,覆盖安装
示例:
[root@centos71d1 ~]# yum -y install gcc
#安装gcc,“-y”表示自动回答“yes”
升级程序包:
yum update [package1] [package2] […]
yum downgrade package1 [package2] […]
“yum update”类似于“rpm -Uvh”,表示升级
“yum downgrade”类似于“rpm -Uvh --oldpackage”,表示降级
检查可用升级:
yum check-update
示例:
[root@centos71d1 ~]# yum check-update
功能类似于 [root@centos71d1 ~]# yum list updates
[root@centos71d1 ~]# yum check-update tar
tar.x86_64 2:1.26-34.el7 base
....
#检查tar的升级包
[root@centos71d1 ~]# yum list installed tar
tar.x86_64 2:1.26-29.el7 @anaconda
....
#查看当前系统中的tar版本
[root@centos71d1 ~]# yum -y update tar
#升级tar
卸载程序包:
yum remove | erase package1 [package2] […]
示例:
[root@centos71d1 ~]# yum remove cpp
#卸载cpp,默认会将依赖cpp的gcc一同卸载
查看程序包information:
yum info […]
示例:
[root@centos71n1 ~]# yum info gcc
类似于 [root@centos71n1 ~]# rpm -qi gcc
#“yum info gcc”查询的是线上软件仓库的程序包信息;“rpm -qi gcc”查询本地已经安装的程序包的信息
查看指定的特性(可以是某文件)是由哪个程序包所提供:
yum provides | whatprovides feature1 [feature2] […]
示例:
[root@centos71n1 ~]# yum provides /bin/ls
#查看ls这个文件由哪个程序包提供,类似于rpm -qf命令
清理本地缓存:
yum clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]
构建缓存:
yum makecache
搜索:
yum search string1 [string2] […]
以指定的关键字搜索程序包名及summary信息
示例:
[root@centos71n1 ~]# yum search bash
#搜索含有bash字符串的程序包或程序包概要信息
查看指定包所依赖的capabilities:
yum deplist package1 [package2] […]
示例:
[root@centos71n1 ~]# yum deplist gcc
#查看gcc程序包依赖于哪些功能特性,和对应的程序包
查看yum事务历史:
yum history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats]
示例:
[root@centos71n1 ~]# yum -y remove cpp
[root@centos71n1 ~]# yum history
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
5 | root <root> | 2018-07-12 17:42 | Erase | 2
#查询yum事务记录,卸载了两个程序包
[root@centos71n1 ~]# yum history summary
#查看yum事务摘要记录
[root@centos71n1 ~]# yum history packages-list gcc
#查询gcc程序包的相关yum事务记录
安装或升级本地程序包:
* yum localinstall rpmfile1 [rpmfile2] […]
(maintained for legacy reasons only – use install)* yum localupdate rpmfile1 [rpmfile2] […]
(maintained for legacy reasons only – use update)
* 在新版本的yum中,可直接使用install和update,只有在较老的版本中,才需要使用localinstall和localupdate
包组管理相关命令:
* yum groupinstall group1 [group2] […]
* yum groupupdate group1 [group2] […]
* yum grouplist [hidden] [groupwildcard] […]
* yum groupremove group1 [group2] […]
* yum groupinfo group1 […]
示例:
[root@centos71n1 ~]# yum grouplist
#显示包组
[root@centos71n1 ~]# yum groupinstall "Development Tools"
#安装包组“Development Tools”
[root@centos71n1 ~]# yum groupinfo "Development Tools"
#查看包组“Development Tools”的信息