CentOS换源
1、备份当前yum源防止出现意外还可以还原回来
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base-repo.bak
2、使用wget下载阿里yum源repo文件到/etc/yum.repos.d/目录
使用之前请确保已经安装wget,如未安装请执行下面一条命令来安装 yum install -y wget
centos 7
wget -P /etc/yum.repos.d/ wget http://mirrors.aliyun.com/repo/Centos-7.repo
centos 8
wget -P /etc/yum.repos.d/ wget http://mirrors.aliyun.com/repo/Centos-8.repo
3、 清理旧包
yum clean all
4、把下载下来阿里云repo文件设置成为默认源
cd /etc/yum.repos.d/
mv Centos-7.repo CentOS-Base.repo #centos 7
mv Centos-8.repo CentOS-Base.repo #centos 8
5、 生成阿里云yum源缓存并更新yum源
yum makecache
yum update
非阿里云服务器会出现 Couldn’t resolve host ‘mirrors.cloud.aliyuncs.com’ 信息,不影响使用。
也可使用下面命令解决。
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS
6、查看存储库是否更换成功
yum repolist
类似输出: