温馨提示×

yum命令如何使用

小樊
50
2026-07-11 01:54:24
栏目: 编程语言

yum(Yellowdog Updater, Modified)是 CentOS / RHEL / Fedora 等早期版本 中常用的 RPM 包管理工具,主要用于安装、更新、删除软件包。下面按常见使用场景给你一个实用速查表。


一、yum 基本语法

yum [选项] [命令] [包名]

二、常用 yum 命令

1️⃣ 查询软件包

yum search nginx          # 搜索软件包
yum list                  # 列出所有可用包
yum list installed        # 已安装的包
yum info nginx            # 查看包信息

2️⃣ 安装软件

yum install nginx
yum install -y nginx      # 自动确认(非交互)

3️⃣ 更新软件

yum update                # 更新所有软件包
yum update nginx          # 只更新指定包
yum check-update          # 查看可更新的包

4️⃣ 删除软件

yum remove nginx
yum erase nginx           # 和 remove 一样

5️⃣ 清理缓存

yum clean all             # 清理所有缓存
yum makecache             # 重建缓存

6️⃣ 查看依赖关系

yum deplist nginx

7️⃣ 查看某个文件属于哪个包

yum provides /usr/bin/vim
yum provides "*/ifconfig"

8️⃣ 查看 yum 历史

yum history
yum history undo 3        # 撤销第 3 次操作

三、仓库(Repository)管理

查看仓库

yum repolist
yum repolist all

禁用 / 启用仓库

yum --disablerepo=epel install xxx
yum --enablerepo=epel install xxx

四、常见错误与解决

❌ 没有可用软件包

yum install epel-release

很多软件在 EPEL 仓库


❌ 网络问题

ping mirrors.aliyun.com
yum clean all
yum makecache

五、CentOS 8 / RHEL 8 注意

yum 已被 dnf 取代

dnf install nginx

yum 仍可作为 dnf 的兼容命令使用。


六、常用组合示例

yum install -y wget curl vim
yum update -y
yum remove -y docker

七、总结速查表

功能 命令
安装 yum install
删除 yum remove
更新 yum update
搜索 yum search
查看信息 yum info
清理缓存 yum clean all

如果你愿意,可以告诉我:

  • ✅ 你用的是 CentOS 7 / 8 / Rocky / Alma / RHEL
  • ✅ 想安装 什么软件

我可以给你精确命令和仓库配置

0