当我们使用yum进行软件包安装时,发生如下报错:
并且排除:
1.ping网络未连接问题
2.通过yum --version排除yum未正确安装问题
通过报错信息得出:该报错为未正常访问镜像源
如何解决:
1.重新配置yum源
- 删除原有的 yum 源配置文件:进入
/etc/yum.repos.d/
目录,删除该目录下的所有文件(建议先备份或移动到其他位置,以防万一)。执行命令:rm -f /etc/yum.repos.d/*
- 重新下载合适的 yum 源:例如,如果使用阿里云的源,可以执行以下命令下载 CentOS 的 base 源和 epel 源(需要 root 权限):
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
- 清理 yum 缓存:执行命令
yum clean all
。 - 重新生成 yum 缓存:执行命令
yum makecache
。 - 更新系统:执行命令
yum update
,更新系统软件包。
最终就能够正确使用yum命令去下载软件啦!如仍未解决请留言👇