阿里7.x
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
yum makecache
备份源yum源
如果是国内下载的CentOS很可能国内YUM源已经设置好了。
备份/etc/yum.repos.d/下的*.repo文件
删除全部
推荐使用#清华大学 https://mirrors.cnnic.cn/help/centos/
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.bak
cp CentOS-Base.repo CentOS-Base.repo.bak
#阿里镜像源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
#腾讯
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo
yum makecache # 生成yum缓存
查看系统可用的yum源和所有的yum源
yum repolist enabled
yum repolist all
# 对于 CentOS 7
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org/centos|baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos|g' \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo
# 对于 CentOS 8
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org/$contentdir|baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos|g' \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo
yum makecache # 生成yum缓存