1. 切换目录
cd /etc/yum.repos.d/
2. 备份之前的yum
源
mv CentOS-Base.repo CentOS-Base.repo.bk
3. 下载阿里云yum
源
# 根据对应的Centos版本下载对应的yum源
CentOS 6:
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo
CentOS 7:
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
centos8(centos8官方源已下线,建议切换centos-vault源)
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
4. 缓存到本地
yum makecache
Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again
建议用如下方法解决:检查/etc/yum.repos.d/下是否有epel.repo文件,如果有,重命名为epel.repo_bak 千万不能以.repo格式备份,然后在执行一次上面的命令即可!