文档首页> 云计算产品> Linux CentOS 6/7 一键更换为阿里yum源

Linux CentOS 6/7 一键更换为阿里yum源

发布时间:2022-11-08 21:36       

虽然不是什么难事,既然用到了就记录一下吧!

 

阿里官方镜像源:https://developer.aliyun.com/mirror/

 

知道你们懒直接上一键脚本

 

「CentOS 6」

 

yum install -y wget;cd /etc/yum.repos.d/;mv CentOS-Base.repo CentOS-Base.repo.bak;wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo;yum clean all;yum makecache

 

「CentOS 7」

 

yum install -y wget;cd /etc/yum.repos.d/;mv CentOS-Base.repo CentOS-Base.repo.bak;wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo;yum clean all;yum makecache

 

1、安装wget

 

yum install -y wget

 

不想安装 wget 的话可以尝试一下 curl

 

2、备份 CentOS-Base.repo 防止翻车

 

cd /etc/yum.repos.d/

mv CentOS-Base.repo CentOS-Base.repo.bak

 

3、下载 CentOS-Base.repo 文件,根据自己是 CentOS 6 还是 7 更改下述加粗内容

 

「CentOS 6」

 

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

 

「CentOS 7」

 

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

 

如果 wget 的时候出现了问题(比如说DNS设置错误等疑难杂症)

 

可以尝试一下手动下载 repo 文件,然后用 FileZilla 上传。