Cenos 更换阿里云源

centos7更换

检查DNS,并刷新

systemctl restart NetworkManager

清空YUM缓存

yum clean all

更换阿里云源

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

如果没wget,别的系统下个导入离线安装rpm包

dnf reinstall --downloadonly --downloaddir=/home/centos
#或
yum --downloadonly --downloaddir=/home/centos update
yum install /home/centos/*.rpm

生成缓存

yum makecache

centos8更换

检查DNS,并刷新

systemctl restart NetworkManager

备份源

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

清空YUM缓存

yum clean all

更换阿里云源

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.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

生成缓存

yum makecache

最后一步到位

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
yum clean all && yum makecache

centos stream9 更换

1.备份现有的yum源配置

cp /etc/yum.repos.d /etc/yum.repos.d.backup -r

2.下载阿里云的yum源配置文件

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-vault-9.repo
#或
wget -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-vault-9.repo

3.清理yum源缓存,生成新的

sudo yum clean all
sudo yum makecache