点击访问 Linux 命令大全 >>
前面章节介绍了 apt 软件包管理工具,本章节将介绍 yum 软件包管理工具。
yum 是 Yellowdog update Modified 的简称,yum 的宗旨是自动化的升级、安装/移除 rpm 安装包(也就是说 yum 这个命令它的操作对象是 RPM 包),收集 rmp 的相关信息,检查依赖性,并提示用户解决。
yum 的关键之处是要有可靠的软件的仓库(repository),仓库可以是 http/https 或者 ftp 站点,也可以是本地的软件池。但是必须包含 rpm 的 header,rmp 的 header 包括了 rmp 的各种信息,包括描述、功能、提供的文件、依赖性等,正是收集了这些信息,才能自动化的完成余下的任务。
yum 本身就是运行在 linux 上的自动管理安装包的系统。
yum 的理念是使用一个中心仓库 (repository) 管理应用程序相互关系,根据计算出来的软件依赖关系进行相关的升级、安装、删除等等操作,减少了Linux 用户一直头痛的依赖问题。这一点上,yum 和 apt 相同,apt 原为 debian 的 deb 类型软件管理所使用,但是现在也能用到 RedHat 门下的 rpm 了。
注意:
Linux 下的 RPM 的全称是“RedHat Package Manager”,最早是 Red Hat 公司开发的,后来在 CentOS、Fedora、SUSE 都用它。而 rpm 包则是软件编译完成后按照 RPM 机制打包起来的一个文件,可以用 rpm 命令安装的一个软件安装包,它省去了 Linux 软件安装中编译的步骤,安装成功后软件就可以用了。
RPM 包的名称规则示例:ttpd-manual- 2.0.40-21.i386.rpm,说明如下:
ttp-manual 是软件包的名称;
2 是主版本号;
0 是次版本号;
40 是次版本号;
21 是编译的次数;
i386 是适合的平台;
.rpm 说明这是一个RPM包;
yum 的一切配置信息都存储在 /etc/yum.conf 文件中,这是 yum 系统中最重要的内容。
yum.conf 一般分为 main 和 repository 两部分,但是默认情况下只有 main 部分。每一个 yum.conf 都只能有一个main 部分。repository 部分定义了每个源/服务器的具体配置,可以有一到多个,常位于 /etc/yum.repo.d 目录下的各文件中。
使用 cat /etc/yum.conf 查看该文件的内容。如下:
[root@localhost ~]# cat /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=https://bugs.centos.org/set_project.php?project_id=23&ref=https://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
# This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
# It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.dyum.conf 配置文件说明:
cachedir:此项为 yum 下载的 RPM 包的缓存目录,yum 在此存储下载的 rpm 包和数据库
keepcache:缓存是否保存,1 表示安装后保留软件包,0 表示安装后删除软件包
debuglevel:出错日志级别,级别为0-10,默认为2(只保留安装和删除记录)
logfile:存放系统更新软件的记录,用户可以在该配置项配置的文件中检查自己在过去的日子都做了哪些更新
pkgpolicy: 包的策略。一共有两个选项,newest和last,这个作用是如果你设置了多个repository,而同一软件在不同的repository中同时存 在,yum应该安装哪一个,如果是newest,则yum会安装最新的那个版本。如果是last,则yum会将服务器id以字母表排序,并选择最后的那个服务器上的软件安装。
distroverp:指定一个软件包,yum会根据这个包判断你的发行版本,默认是RedHat-release,也可以是安装的任何针对自己发行版的rpm包。
tolerent:也有1和0两个选项,表示yum是否容忍命令行发生与软件包有关的错误,比如你要安装1,2,3三个包,而其中3此前已经安装了,如果你设为1,则yum不会出现错误信息。默认是0。
exactarch:有两个选项1和0,代表是否只升级和你安装软件包cpu体系一致的包,如果设为1,则如你安装了一个i386的rpm,则yum不会用1686的包来升级。
retries:网络连接发生错误后的重试次数,如果设为 0,则会无限重试。
obsoletes:这是一个update的参数,具体请参阅yum(8),简单的说就是相当于upgrade,允许更新陈旧的RPM包。
gpgcheck:是否检查GPG(GNU Private Guard),一种密钥方式签名。
plugins:否允许使用插件,默认是0不允许,但是我们一般会用yum-fastestmirror这个插件。
installonly_limit:允许保留多少个内核包。
exclude:屏蔽不想更新的RPM包,可用通配符,多个RPM包之间使用空格分离。
reposdir:该选项用户指定 .repo 文件的绝对路径。.repo 文件包含软件仓库的信息 (作用与 /etc/yum.conf 文件中的 [repository] 片段相同)。 reposdir=[包含 .repo 文件的目录的绝对路径]
bugtracker_url:追踪 bug 路径
Usage: yum [options] COMMAND
List of Commands:
check 检查 RPM 数据库问题
check-update 检查是否有可用的软件包更新
clean 删除缓存数据
deplist 列出软件包的依赖关系
distribution-synchronization 已同步软件包到最新可用版本
downgrade 降级软件包
erase 从系统中移除一个或多个软件包
fs Acts on the filesystem data of the host, mainly for removing docs/lanuages for minimal hosts.
fssnapshot Creates filesystem snapshots, or lists/deletes current snapshots.
groups 显示或使用、组信息
help 显示用法提示
history 显示或使用事务历史
info 显示关于软件包或组的详细信息
install 向系统中安装一个或多个软件包
list 列出一个或一组软件包
load-transaction 从文件名中加载一个已存事务
makecache 创建元数据缓存
provides 查找提供指定内容的软件包
reinstall 覆盖安装软件包
repo-pkgs 将一个源当作一个软件包组,这样我们就可以一次性安装/移除全部软件包。
repolist 显示已配置的源
search 在软件包详细信息中搜索指定字符串
shell 运行交互式的 yum shell
swap Simple way to swap packages, instead of using shell
update 更新系统中的一个或多个软件包
update-minimal Works like upgrade, but goes to the 'newest' package match which fixes a problem that affects your system
updateinfo Acts on repository update information
upgrade 更新软件包同时考虑软件包取代关系
version 显示机器和/或可用的源版本。
Options:
-h, --help 显示此帮助消息并退出
-t, --tolerant 忽略错误
-C, --cacheonly 完全从系统缓存运行,不升级缓存
-c [config file], --config=[config file] 配置文件路径
-R [minutes], --randomwait=[minutes] 命令最长等待时间
-d [debug level], --debuglevel=[debug level] 调试输出级别
--showduplicates 在 list/search 命令下,显示源里重复的条目
-e [error level], --errorlevel=[error level] 错误输出级别
--rpmverbosity=[debug level name] RPM 调试输出级别
-q, --quiet 静默执行
-v, --verbose 详尽的操作过程
-y, --assumeyes 回答全部问题为是
--assumeno 回答全部问题为否
--version 显示 Yum 版本然后退出
--installroot=[path] 设置安装根目录
--enablerepo=[repo] 启用一个或多个软件源(支持通配符)
--disablerepo=[repo] 禁用一个或多个软件源(支持通配符)
-x [package], --exclude=[package] 采用全名或通配符排除软件包
--disableexcludes=[repo] 禁止从主配置,从源或者从任何位置排除
--disableincludes=[repo] disable includepkgs for a repo or for everything
--obsoletes 更新时处理软件包取代关系
--noplugins 禁用 Yum 插件
--nogpgcheck 禁用 GPG 签名检查
--disableplugin=[plugin] 禁用指定名称的插件
--enableplugin=[plugin] 启用指定名称的插件
--skip-broken 忽略存在依赖关系问题的软件包
--color=COLOR 配置是否使用颜色
--releasever=RELEASEVER 在 yum 配置和 repo 文件里设置 $releasever 的值
--downloadonly 仅下载而不更新
--downloaddir=DLDIR 指定一个其他文件夹用于保存软件包
--setopt=SETOPTS 设置任意配置和源选项
--bugfix Include bugfix relevant packages, in updates
--security Include security relevant packages, in updates
--advisory=ADVS, --advisories=ADVS Include packages needed to fix the given advisory, in updates
--bzs=BZS Include packages needed to fix the given BZ, in updates
--cves=CVES Include packages needed to fix the given CVE, in updates
--sec-severity=SEVS, --secseverity=SEVS
Include security relevant packages matching the severity, in updates可使用 yum install 和 yum groupinstall 命令安装软件包。语法如下:
yum install ## 全部安装
yum install package1 ## 安装指定的安装包package1
yum groupinsall group1 ## 安装程序组group1实例:使用 yum install 安装 tree 软件包,如下:
[root@localhost ~]# yum remove tree
已加载插件:fastestmirror
正在解决依赖关系
--> 正在检查事务
---> 软件包 tree.x86_64.0.1.6.0-10.el7 将被 删除
--> 解决依赖关系完成
依赖关系解决
=======================================================================================================================================
Package 架构 版本 源 大小
=======================================================================================================================================
正在删除:
tree x86_64 1.6.0-10.el7 @base 87 k
事务概要
=======================================================================================================================================
移除 1 软件包
安装大小:87 k
是否继续?[y/N]:Y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在删除 : tree-1.6.0-10.el7.x86_64 1/1
验证中 : tree-1.6.0-10.el7.x86_64 1/1
删除:
tree.x86_64 0:1.6.0-10.el7
完毕!
[root@localhost ~]# clear
[root@localhost ~]# tree
-bash: /usr/bin/tree: 没有那个文件或目录
[root@localhost ~]#
[root@localhost ~]# yum install tree
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
updates/7/x86_64/primary_db | 3.7 MB 00:00:00
正在解决依赖关系
--> 正在检查事务
---> 软件包 tree.x86_64.0.1.6.0-10.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=======================================================================================================================================
Package 架构 版本 源 大小
=======================================================================================================================================
正在安装:
tree x86_64 1.6.0-10.el7 base 46 k
事务概要
=======================================================================================================================================
安装 1 软件包
总下载量:46 k
安装大小:87 k
Is this ok [y/d/N]: Y
Downloading packages:
tree-1.6.0-10.el7.x86_64.rpm | 46 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : tree-1.6.0-10.el7.x86_64 1/1
验证中 : tree-1.6.0-10.el7.x86_64 1/1
已安装:
tree.x86_64 0:1.6.0-10.el7
完毕!
## 使用已经安装完成的 tree 查看当前目录文件的树形结构
[root@localhost ~]# tree
.
├── anaconda-ks.cfg
├── data1
├── data2
│ └── data.txt
├── hello_bak.txt
├── tmp
│ ├── data
│ │ ├── hello_bak.txt
│ │ ├── hello.txt
│ │ └── hello.txt~
│ └── data1
│ └── data.txt
├── tree-1.5.3-3.el6.x86_64.rpm
├── tree-1.6.0-10.el7.x86_64.rpm
└── vim-8.2.1253-1.1.x86_64.rpm
5 directories, 10 files
[root@localhost ~]#可以使用 yum update 更新软件包,或者使用 yun check-update 检查程序更新。语法如下:
yum update package1 ## 更新指定程序包package1
yum check-update ## 检查可更新的程序
yum upgrade package1 ## 升级指定程序包package1
yum groupupdate group1 ## 升级程序组group1实例:将本地的 tree-1.5.3 升级到 tree-1.6.0。如下:
## 查看本地 tree 的版本
[root@localhost ~]# tree --version
tree v1.5.3 (c) 1996 - 2009 by Steve Baker, Thomas Moore, Francesc Rocher, Kyosuke Tokoro
## 将 tree 升级到最新版本
[root@localhost ~]# yum update tree
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 tree.x86_64.0.1.5.3-3.el6 将被 升级
---> 软件包 tree.x86_64.0.1.6.0-10.el7 将被 更新
--> 解决依赖关系完成
依赖关系解决
=======================================================================================================================================
Package 架构 版本 源 大小
=======================================================================================================================================
正在更新:
tree x86_64 1.6.0-10.el7 base 46 k
事务概要
=======================================================================================================================================
升级 1 软件包
总下载量:46 k
Is this ok [y/d/N]: Y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
tree-1.6.0-10.el7.x86_64.rpm | 46 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在更新 : tree-1.6.0-10.el7.x86_64 1/2
清理 : tree-1.5.3-3.el6.x86_64 2/2
验证中 : tree-1.6.0-10.el7.x86_64 1/2
验证中 : tree-1.5.3-3.el6.x86_64 2/2
更新完毕:
tree.x86_64 0:1.6.0-10.el7
完毕!
## 查看 tree 软件版本
[root@localhost ~]# tree --version
tree v1.6.0 (c) 1996 - 2011 by Steve Baker, Thomas Moore, Francesc Rocher, Kyosuke Tokoro可使用 yum remove 命令删除软件包,使用 yum groupremove 删除软件包组。语法如下:
yum remove package1 ## 删除程序包package1
yum groupremove group1 ## 删除程序组group1实例:使用 yum remove 卸载 tree 软件包。如下:
[root@localhost ~]# yum remove tree
已加载插件:fastestmirror
正在解决依赖关系
--> 正在检查事务
---> 软件包 tree.x86_64.0.1.6.0-10.el7 将被 删除
--> 解决依赖关系完成
依赖关系解决
=======================================================================================================================================
Package 架构 版本 源 大小
=======================================================================================================================================
正在删除:
tree x86_64 1.6.0-10.el7 @base 87 k
事务概要
=======================================================================================================================================
移除 1 软件包
安装大小:87 k
是否继续?[y/N]:Y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在删除 : tree-1.6.0-10.el7.x86_64 1/1
验证中 : tree-1.6.0-10.el7.x86_64 1/1
删除:
tree.x86_64 0:1.6.0-10.el7
完毕!可使用 yum deplist 命令查看软件包的依赖关系。语法如下:
yum deplist package1 ## 查看程序package1依赖情况例如:查看 tree 软件包的依赖关系,如下:
[root@localhost ~]# yum deplist tree
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
软件包:tree.x86_64 1.6.0-10.el7
依赖:libc.so.6(GLIBC_2.14)(64bit)
provider: glibc.x86_64 2.17-307.el7.1
依赖:rtld(GNU_HASH)
provider: glibc.x86_64 2.17-307.el7.1
provider: glibc.i686 2.17-307.el7.1可使用 yum info 命令查看软件包的详细信息。语法如下:
yum info package1 ## 显示安装包信息package1
yum list ## 显示所有已经安装和可以安装的程序包
yum list package1 ## 显示指定程序包安装情况package1
yum groupinfo group1 ## 显示程序组group1信息yum search string 根据关键字string查找安装包例如:查看 tree 软件包的详细信息,如下:
[root@localhost ~]# yum info tree
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
已安装的软件包
名称 :tree
架构 :x86_64
版本 :1.6.0
发布 :10.el7
大小 :87 k
源 :installed
来自源:base
简介 : File system tree viewer
网址 :https://mama.indstate.edu/users/ice/tree/
协议 : GPLv2+
描述 : The tree utility recursively displays the contents of directories in a
: tree-like format. Tree is basically a UNIX port of the DOS tree
: utility.