CentOS yum、dnf安装、卸载软件 作者:马育民 • 2026-09-26 15:12 • 阅读:10001 # 介绍 ### 区分版本 - CentOS7:包管理器 **yum** - CentOS8/Stream:默认 **dnf**。dnf 是yum升级版,命令几乎通用 **注意:**CentOS8 官方已停止维护,yum源默认失效,生产优先 CentOS7 或 RockyLinux/AlmaLinux # 一、基础查询命令 ### 查看已安装的所有软件包 ```bash yum list installed # CentOS7 dnf list installed # CentOS8/Stream ``` ### 搜索软件(找包名,非常常用) ``` yum search nginx dnf search nginx ``` ### 查看软件信息(版本、描述) ``` yum info nginx ``` # 二、安装软件 ### 安装单个软件 ```bash yum install nginx -y dnf install nginx -y ``` **解释:**`-y` 自动确认,不加-y会交互式询问是否安装 ### 一次性安装多个包,空格隔开 ``` yum install wget net-tools telnet -y ``` ### 安装指定版本 ``` yum install nginx-1.20.1 -y ``` # 三、卸载软件 **重点:** 卸载前确认包名,**不要误删系统基础包**(如glibc、systemd,删了系统直接崩溃) ### yum/dnf 卸载(推荐) 删除软件本身,**会删除该包依赖的、没有其他程序在用的依赖包**;配置文件默认保留。 ```bash # 卸载软件 yum remove nginx -y dnf remove nginx -y ``` ##### 卸载多个软件 ``` yum remove wget telnet -y ``` ### 2. 彻底卸载(删除配置文件) `erase` 和 `remove` 几乎一样,部分版本会一并清理配置 ```bash yum erase nginx -y ``` # 四、更新软件 ### 更新单个软件 ```bash yum update nginx -y ``` ### 更新全部已安装包(谨慎,生产环境先测试) ``` yum update -y ``` # 五、yum仓库常用操作 ### 清理缓存 ```bash yum clean all ``` ### 重建缓存 ``` yum makecache ``` ### 查看启用的仓库 ``` yum repolist enabled ``` 原文出处:/show_1GW47Oj7UZho.html