“ 目录:RHCA+ -> 6 软件仓库 -> 36 yum命令(查询、安装、升级和卸载软件包) ”
安装软件包;语法格式:yum [参数] 动作 软件包名
命令中支持使用通配符
参数 | 作用 |
-y | 非交互式安装,所有提示都同意 |
--nogpgcheck | 安装时跳过gpg签名验证 |
--downloadonly | 只下载软件包 |
--downloaddir=/root | 指定下载的软件包保存位置 |
动作 | 作用 |
repolist | all:查看所有仓库列表 enabled(默认):查看允许使用的 disabled:查看禁用的 |
yum-config-manager | 查看仓库的详细配置 --enable:启用仓库 --disable:禁用仓库 |
list | all:查看仓库中所有软件包 available:可用的,仓库中有但尚未安装的 installed:已经安装的 updates:可用的升级 |
search | 查找与关键字相关的所有软件包 |
info | 查看软件包详细信息 |
provides | 查看指定文件或特性是由哪个软件包安装生成的 |
whatprovides | |
install | 安装软件包;不带-y参数会每个软件包都让确认 |
localinstall | 通过本地rpm包进行安装 |
reinstall | 重新安装软件包 |
update | 升级软件包;不带包名会升级所有软件包 |
remove | 卸载软件包;不推荐用 |
check-update | 检查可更新的软件包 |
history | 查看历史记录 |
langavailable | 查看语言包 |
langinstall | 安装语言包 |
1、查询
[root@wuzuniao ~]# yum repolist #查看软件仓库列表
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
repo id repo name status
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,791
pmm2-client-release-x86_64/7Server PMM2 Client release/x86_64 YUM repository 43
prel-release-noarch/7Server Percona Release release/noarch YUM repository 8
telemetry-release-x86_64/7Server Percona Telemetry release/x86_64 YUM repository 0
wuzuniao wuzuniao 4,305
repolist: 18,147
[root@wuzuniao ~]# yum list #查询所有已安装和可安装的软件包
Loaded plugins: langpacks
Installed Packages
GConf2.x86_64 3.2.6-8.el7 @anaconda/7.0
ModemManager.x86_64 1.1.0-6.git20130913.el7 @anaconda/7.0
ModemManager-glib.x86_64 1.1.0-6.git20130913.el7 @anaconda/7.0
#软件名 版本 所在位置(光盘)
[root@wuzuniao ~]# yum list ibus #查看具体的软件包安装情况;输入中文需要的软件包
Loaded plugins: langpacks
Installed Packages
ibus.x86_64 1.5.3-11.el7 @anaconda/7.0
Available Packages
ibus.i686 1.5.3-11.el7 wuzuniao
[root@wuzuniao ~]# yum search samba #查找与关键字相关的所有软件包
Loaded plugins: langpacks
=============================== N/S matched: samba ===============================
samba-client.x86_64 : Samba client programs
samba-common.x86_64 : Files used by both Samba servers and clients
samba-libs.i686 : Samba libraries
samba-libs.x86_64 : Samba libraries
samba-python.x86_64 : Samba Python libraries
samba-winbind.x86_64 : Samba winbind
samba-winbind-modules.i686 : Samba winbind modules
samba-winbind-modules.x86_64 : Samba winbind modules
samba.x86_64 : Server and Client software to interoperate with Windows machines
Name and summary matches only, use "search all" for everything.
[root@wuzuniao ~]# yum info samba #查询软件包的详细信息
Loaded plugins: langpacks
Available Packages #没有安装
Name : samba #包名
Arch : x86_64 #硬件平台
Version : 4.1.1 #版本
Release : 31.el7 #发布版本
Size : 527 k #大小
Repo : wuzuniao #在光盘上,yum源名字
Summary : Server and Client software to interoperate with Windows machines
URL : http://www.samba.org/
License : GPLv3+ and LGPLv3+
Description : Samba is the standard Windows interoperability suite of programs for
: Linux and Unix.
[root@wuzuniao ~]# yum provides "*/librabbitmq.so.4" #缺少某个库的依赖时,可以查询下它在哪个包里面
Last metadata expiration check: 0:12:56 ago on Tue 15 Apr 2025 10:06:09 PM CST.
librabbitmq-0.11.0-7.el9.x86_64 : Client library for AMQP
Repo : appstream
Matched from:
Filename : /usr/lib64/librabbitmq.so.4
[root@wuzuniao ~]# yum provides "iostat" #查看指定命令属于哪个包
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:1:09:21 前,执行于 2025年06月28日 星期六 22时10分51秒。
sysstat-11.7.3-2.el8.x86_64 : Collection of performance monitoring tools for Linux
仓库 :AppStream
匹配来源:
文件名 :/usr/bin/iostat
[root@wuzuniao ~]#
2、安装
语法格式:yum -y install 包名
[root@wuzuniao ~]# yum install -y xterm #安装后出现“Complete!”则代表配置正确(rhcl8可使用dnf)
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package xterm.x86_64 0:295-3.el7 will be installed
--> Processing Dependency: libXaw.so.7()(64bit) for package: xterm-295-3.el7.x86_64
--> Running transaction check
---> Package libXaw.x86_64 0:1.0.11-6.1.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===================================================================================
Package Arch Version Repository Size
===================================================================================
Installing:
xterm x86_64 295-3.el7 wuzuniao 455 k
Installing for dependencies:
libXaw x86_64 1.0.11-6.1.el7 wuzuniao 189 k
Transaction Summary
===================================================================================
Install 1 Package (+1 Dependent package)
Total download size: 644 k
Installed size: 1.7 M
Downloading packages:
-----------------------------------------------------------------------------------
Total 6.1 MB/s | 644 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libXaw-1.0.11-6.1.el7.x86_64 1/2
Installing : xterm-295-3.el7.x86_64 2/2
Verifying : libXaw-1.0.11-6.1.el7.x86_64 1/2
Verifying : xterm-295-3.el7.x86_64 2/2
Installed:
xterm.x86_64 0:295-3.el7
Dependency Installed:
libXaw.x86_64 0:1.0.11-6.1.el7
Complete!
[root@wuzuniao ~]#
3、升级
yum源服务器中软件包版本要比本机安装的软件包版本高
[root@wuzuniao ~]# yum -y update xterm #升级软件包
Loaded plugins: langpacks
wuzuniao | 4.1 kB 00:00:00
No packages marked for update
[root@wuzuniao ~]#
4、卸载
会同时卸载所有与该包有依赖关系的其他软件包,即便依赖包是系统运行必备文件,也会卸载;可能会让系统崩溃
确认卸载的包和它的依赖包不被系统需要后才能用,否则不建议
[root@wuzuniao ~]# yum remove xterm #卸载xterm软件包
Loaded plugins: langpacks
Resolving Dependencies
--> Running transaction check
---> Package xterm.x86_64 0:295-3.el7 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================== Package Arch Version Repository Size
==================================================================================
Removing:
xterm x86_64 295-3.el7 @wuzuniao 1.2 M
Transaction Summary
==================================================================================
Remove 1 Package
Installed size: 1.2 M
Is this ok [y/N]: y #同意
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : xterm-295-3.el7.x86_64 1/1
Verifying : xterm-295-3.el7.x86_64 1/1
Removed:
xterm.x86_64 0:295-3.el7
Complete!
[root@wuzuniao ~]#
5、只下载软件包
适用于外网下载yum仓库里的包,并且会自动下载相关依赖包,自己再拷贝到内网去安装,极大减少安装复杂度
[root@wuzuniao ~]# yum install --downloadonly --downloaddir=/root httpd #只下载httpd相关软件包,并保存到/root目录;如果安装过,install替换为reinstall即可下载
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:0:28:12 前,执行于 2024年04月27日 星期六 18时22分16秒。
依赖关系解决。
================================================================================
软件包 架构 版本 仓库 大小
================================================================================
Installing:
httpd x86_64 2.4.37-10.module+el8+2764+7127e69e AppStream 1.4 M
安装依赖关系:
apr x86_64 1.6.3-9.el8 AppStream 125 k
apr-util x86_64 1.6.1-6.el8 AppStream 105 k
httpd-filesystem noarch 2.4.37-10.module+el8+2764+7127e69e AppStream 34 k
httpd-tools x86_64 2.4.37-10.module+el8+2764+7127e69e AppStream 101 k
mod_http2 x86_64 1.11.3-1.module+el8+2443+605475b7 AppStream 156 k
redhat-logos-httpd noarch 80.7-1.el8 BaseOS 25 k
安装弱的依赖:
apr-util-bdb x86_64 1.6.1-6.el8 AppStream 25 k
apr-util-openssl x86_64 1.6.1-6.el8 AppStream 27 k
Enabling module streams:
httpd 2.4
事务概要
================================================================================
安装 9 软件包
总计:2.0 M
安装大小:5.4 M
DNF 只会下载事务所需的软件包。
确定吗?[y/N]: y #确认下载
下载软件包:
完毕!
[root@wuzuniao ~]# ls #验证
apr-1.6.3-9.el8.x86_64.rpm
apr-util-1.6.1-6.el8.x86_64.rpm
apr-util-bdb-1.6.1-6.el8.x86_64.rpm
apr-util-openssl-1.6.1-6.el8.x86_64.rpm
httpd-2.4.37-10.module+el8+2764+7127e69e.x86_64.rpm
httpd-filesystem-2.4.37-10.module+el8+2764+7127e69e.noarch.rpm
httpd-tools-2.4.37-10.module+el8+2764+7127e69e.x86_64.rpm
mod_http2-1.11.3-1.module+el8+2443+605475b7.x86_64.rpm
redhat-logos-httpd-80.7-1.el8.noarch.rpm
[root@wuzuniao ~]# yum install squid #下载squid及其依赖包
Loaded plugins: langpacks, priorities, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package squid.x86_64 7:3.3.8-12.el7_0 will be installed
--> Processing Dependency: perl(Digest::MD5) for package: 7:squid-3.3.8-12.el7_0.x86_64
--> Processing Dependency: libecap.so.2()(64bit) for package: 7:squid-3.3.8-12.el7_0.x86_64
--> Running transaction check
---> Package libecap.x86_64 0:0.2.0-8.el7 will be installed
---> Package perl-Digest-MD5.x86_64 0:2.52-3.el7 will be installed
--> Processing Dependency: perl(Digest::base) >= 1.00 for package: perl-Digest-MD5-2.52-3.el7.x86_64
--> Running transaction check
---> Package perl-Digest.noarch 0:1.17-245.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================================================================================
Installing:
squid x86_64 7:3.3.8-12.el7_0 wuzuniao 2.6 M
Installing for dependencies:
libecap x86_64 0.2.0-8.el7 wuzuniao 20 k
perl-Digest noarch 1.17-245.el7 wuzuniao 23 k
perl-Digest-MD5 x86_64 2.52-3.el7 wuzuniao 30 k
Transaction Summary
===============================================================================================================================================================================================================
Install 1 Package (+3 Dependent packages)
Total download size: 2.6 M
Installed size: 8.7 M
Is this ok [y/d/N]: d #这里直接选择下载
Background downloading packages, then exiting:
(1/4): libecap-0.2.0-8.el7.x86_64.rpm | 20 kB 00:00:00
(2/4): perl-Digest-1.17-245.el7.noarch.rpm | 23 kB 00:00:00
(3/4): perl-Digest-MD5-2.52-3.el7.x86_64.rpm | 30 kB 00:00:00
(4/4): squid-3.3.8-12.el7_0.x86_64.rpm | 2.6 MB 00:00:00
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 29 MB/s | 2.6 MB 00:00:00
exiting because "Download Only" specified
[root@wuzuniao ~]# find / -name libecap-0.2.0-8.el7.x86_64.rpm #找其中一个软件包的保存位置
/var/cache/yum/x86_64/7Server/wuzuniao/packages/libecap-0.2.0-8.el7.x86_64.rpm
/media/cdrom/Packages/libecap-0.2.0-8.el7.x86_64.rpm
[root@wuzuniao ~]# ll /var/cache/yum/x86_64/7Server/wuzuniao/packages/ #查看对应目录下所有软件包,可以看到squid及其依赖已经被下载
total 2728
-rw-r--r--. 1 root root 20400 Apr 2 2014 libecap-0.2.0-8.el7.x86_64.rpm
-rw-r--r--. 1 root root 23436 Apr 3 2014 perl-Digest-1.17-245.el7.noarch.rpm
-rw-r--r--. 1 root root 30520 Apr 3 2014 perl-Digest-MD5-2.52-3.el7.x86_64.rpm
-rw-r--r--. 1 root root 2695660 Sep 3 2014 squid-3.3.8-12.el7_0.x86_64.rpm
[root@wuzuniao ~]#