一、备份原有的yum源配置文件
打开终端,输入以下命令备份 CentOS - Base.repo 文件:
mv /etc/yum.repos.d/CentOS - Base.repo /etc/yum.repos.d/CentOS - Base.repo.backup
二、下载阿里云的yum源配置文件
使用 wget 命令下载阿里云的 CentOS - Base.repo 文件:
wget - O /etc/yum.repos.d/CentOS - Base.repo http://mirrors.aliyun.com/repo/Centos - 7.repo
这里 -O 参数表示将下载的文件保存为指定的文件名。如果你的系统没有 wget ,可以使用 curl 命令来替代:
curl - o /etc/yum.repos.d/CentOS - Base.repo http://mirrors.aliyun.com/repo/Centos - 7.repo
- curl 的 -o 参数同样是指定输出文件名。
三、清理yum缓存并重新生成
1. 清理原有的yum缓存:
yum clean all
2. 重新生成yum缓存:
yum makecache
然后就能正常使用yum了