[命令] CentOS Linux & RHEL 命令 yum (管理软件和软件源)

内容一: 帮助文档相关

1.1 显示 yum 帮助信息

# yum help

1.2 显示 yum 子选项的帮助信息

# yum help <option>

或者:

# yum <option> help

内容二:软件包相关

2.1 安装软件包

2.1.1 交互式安装软件包
# yum install <software>
2.1.2 非交互式安装软件包
# yum -y install <software>

或者:

# yum install <software> -y

2.2 删除软件软件包

2.2.1 交互式删除软件包
# yum remove <software>
2.2.2 非交互式删除软件包
# yum -y remove <software>

或者:

# yum remove <software> -y

2.3 升级软件包

2.3.1 升级软件包
2.3.1.1 交互式升级软件包
# yum update <software>
2.3.1.2 非交互式升级软件包
# yum -y update <software>

或者:

# yum update <software> -y
2.3.2 升级所有软件包
2.3.2.1 升级所有软件包
2.3.2.1.1 交互式升级所有软件包
# yum update
2.3.2.1.2 非交互式升级所有软件包
# yum -y update

或者:

# yum update -y
2.3.2.2 升级所有软件包时允许删除冲突软件
2.3.2.2.1 交互式升级所有软件包时允许删除冲突软件
# yum update --best --allowerasing
2.3.2.2.2 非交互式升级所有软件包时允许删除冲突软件
# yum -y update --best --allowerasing

或者:

# yum update --best --allowerasing -y
2.3.2.3 升级除某软件包外的所有软件包
2.3.2.3.1 交互式升级除某软件包外的所有软件包
# yum update --exclude=<software>
2.3.2.3.2 非交互式升级除某软件包外的所有软件包
# yum -y update --exclude=<software>

或者:

# yum update --exclude=<software> -y
2.3.2.4 使用某 1 个配置文件升级所有软件包
2.3.2.4.1 交互式使用某 1 个配置文件升级所有软件包
# yum ./yum.conf update

(补充:这里以使用 ./yum.conf 配置文件升级所有软件包为例)

2.3.2.4.2 非交互式使用某 1 个配置文件升级所有软件包
# yum -y -c ./yum.conf update

(补充:这里以使用 ./yum.conf 配置文件升级所有软件包为例)

2.3.2.5 显示所有可以升级的软件包
# yum check-update
2.3.2.6 显示所有升级后需要重启才生效的软件包
# dnf needs-restarting --reboothint

2.4 显示软件包

2.4.1 显示软件包
2.4.1.1 显示软件包
# yum list <software>

或者:

# yum list all | grep <software>
2.4.1.2 显示软件包详细信息
# yum info <software>
2.4.1.3 显示软件包的所有可安装版本
# yum list <software> --showduplicate  | sort -r
2.4.2 显示所有软件包
# yum list all

内容三:软件组相关

3.1 安装软件组

3.1.1 交互式安装软件组
# yum groupinstall <group>
3.1.2 非交互式安装软件组
# yum -y groupinstall <group>

或者:

# yum groupinstall <group> -y

3.2 删除软件组

3.2.1 交互式删除软件组
# yum groupremove <group>
3.2.2 非交互式删除软件组
# yum -y groupremove <group>

或者:

# yum groupremove <group> -y

3.3 显示所有可用软件组

# yum group list

内容四:安全相关

4.1 Errata

4.1.1 Errata
4.1.1.1 安装 Errata
4.1.1.1.1 交互式安装 Errata
# yum update --advisory=<errata>
4.1.1.1.2 非交互式安装 Errata
# yum -y update --advisory=<errata>

或者:

# yum update --advisory=<errata> -y
4.1.1.2 显示 Errata 的详细信息
# yum updateinfo <errata>
4.1.2 所有 Errata
4.1.2.1 安装所有 Errata
4.1.2.1.1 交互式安装所有 Errata
# yum update-minimal --security
4.1.2.1.2 非交互式安装所有 Errata
# yum -y update-minimal --security

或者:

# yum update-minimal --security -y
4.1.2.2 显示所有 Errata 和相关软件版本
# yum updateinfo list
4.1.2.3 显示所有 Errata 和相关的 CVE
# yum updateinfo info security

4.2 CVE

4.2.1 CVE
4.2.1.1 安装 CVE
4.2.1.1.1 交互式安装 CVE
# yum update --cve <CVE>
4.2.1.1.2 非交互式安装 CVE
# yum -y update --cve <CVE>

或者:

# yum update --cve <CVE> -y
4.2.2 显示 CVE
4.2.2.1 显示所有 CVE 和相关软件版本
# yum updateinfo list cves
4.2.2.2 显示所有 CVE 和相关的 Errata
# yum updateinfo info security

4.2 安全补丁

4.2.1 安全补丁
4.2.1.1 安装安全补丁
4.2.1.1.1 交互式安装安全补丁
# yum update <security patch>
4.2.1.1.2 非交互式安装安全补丁
# yum -y update <security patch>

或者:

# yum update <security patch> -y
4.2.2 所有安全补丁
4.2.2.1 安装所有安全补丁
4.2.2.1.1 交互式安装所有安全补丁
# yum update --security
4.2.2.1.2 非交互式安装所有安全补丁
# yum -y update --security

或者:

# yum update --security -y
4.2.2.2 显示所有安全补丁
# yum check-update --security

内容五:软件源相关

5.1 显示所有软件源

# yum repolist 

5.2 缓存软件源列表

5.2.1 缓存所有已启用软件源列表
# yum repolist 
5.2.2 清除所有软件源列表缓存
# yum clean all
5.2.3 保存所有软件源列表缓存
# yum makecache

内容六:软件模块相关 (切换软件可用的版本)

6.1 软件模块相关的格式

6.1.1 显示软件模块
6.1.1.1 显示所有软件模块
# yum module list
6.1.1.2 显示某个软件模块
# yum module list | grep <software>
6.1.2 重置软件模块
# yum module reset <module>
6.1.3 设置软件模块
# yum module enable <module>:<version>

6.2 切换软件模块的案例

6.2.1 检测当前软件兼容情况
# yum distro-sync

(注意:需要确保这条命令执行有以后没有报错)

6.2.2 显示所有软件模块
# yum module list | grep podman
container-tools      rhel8 [d]       common [d]                               Most recent (rolling) versions of podman, buildah, skopeo, runc, conmon, runc, conmon, CRIU, Udica, etc as well as dependencies such as container-selinux built and tested together, and updated as frequently as every 12 weeks.
container-tools      1.0             common [d]                               Stable versions of podman 1.0, buildah 1.5, skopeo 0.1, runc, conmon, CRIU, Udica, etc as well as dependencies such as container-selinux built and tested together, and supported for 24 months.                                 
container-tools      2.0             common [d]                               Stable versions of podman 1.6, buildah 1.11, skopeo 0.1, runc, conmon, etc as well as dependencies such as container-selinux built and tested together, and supported as documented on the Application Stream lifecycle page.    
container-tools      3.0             common [d]                               Stable versions of podman 3.0, buildah 1.19, skopeo 1.2, runc, conmon, etc as well as dependencies such as container-selinux built and tested together, and supported as documented on the Application Stream lifecycle page.    
container-tools      4.0             common [d]                               Stable versions of podman 4.0, buildah 1.24, skopeo 1.6, runc, conmon, etc as well as dependencies such as container-selinux built and tested together, and supported as documented on the Application Stream lifecycle page.  

(补充:这里以显示所有和 podman 软件相关的软件模块为例)

6.2.3 设置软件模块
6.2.3.1 重置软件模块
# yum module reset container-tools

(补充:这里以重置 container-tools 软件模块为例)

6.2.3.2 设置软件模块
# yum module enable container-tools:3.0

(补充:这里以设置 container-tools 软件模块版本号为 3.0 为例)

或者:

# yum module enable container-tools:rhel8


补充:
1) 这里以设置最新的 container-tools 软件模块版本号为例
2) 当站主在测试这条命令时,最新的 container-tools 软件模块版本号刚好是 3.0

(注意:有些时候只能设置成最新的软件模块版本号后才能升级到最新的软件)

6.2.3.3 显示设置 container-tools 软件模块版本号为 3.0 时 podman 软件的可用版本
# yum list all | egrep ^podman\.x         
podman.x86_64                                           3.0.1-9.module+el8.6.0+14874+64436299                       rhel-8-for-x86_64-appstream-rpms    

(补充:可以看到此时 podman 软件的可用版本是 3.0.1-9)

6.2.4 重置软件模块
6.2.4.1 重置软件模块
# yum module reset container-tools

(补充:这里以重置 container-tools 软件模块为例)

6.2.4.2 显示 container-tools 软件模块没有设置时 podman 软件的可用版本
# yum list all | egrep ^podman\.x
podman.x86_64                                           2:4.0.2-6.module+el8.6.0+14877+f643d2d6                     rhel-8-for-x86_64-appstream-rpms

(补充:可以看到此时 podman 软件的可用版本是 2:4.0.2-6)

内容七:管理相关

7.1 显示 YUM 历史命令

# yum history

7.2 显示 YUM 安装记录

# yum history info

7.3 操作回滚

# yum history
# yum history undo <ID>

(补充:上面第 1 条命令会实现操作的 ID 号,在第 2 条命令中写入那个 ID 号就可以取消那次操作)