1、备份系统本身的yum源文件
- mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2、下载新的CentOS-Base.repo 到/etc/yum.repos.d/
CentOS 5
- wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
CentOS 6 (如果不可用,请拉到最底部使用新方法)
- wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
由于各大镜像站(阿里、163、清华等)都不再维护 CentOS 6 的 Yum 源镜像,当前找到如下办法:
直接编辑 /etc/yum.repos.d/Centos-Base.repo ,清空所有内容,替换如下代码:
- vi /etc/yum.repos.d/Centos-Base.repo
- [base]
- name=CentOS-6
- failovermethod=priority
- baseurl=https://vault.centos.org/6.9/os/x86_64/
- gpgcheck=0
CentOS 7
- wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
CentOS 8
进入yum.repos.d目录
备份3个源文件
- cp CentOS-Base.repo CentOS-Base.repo.bak
- cp CentOS-AppStream.repo CentOS-AppStream.repo.bak
- cp CentOS-Extras.repo CentOS-Extras.repo.bak
修改3个文件中的地址:
- sed -i 's/mirrorlist=/#mirrorlist=/g' CentOS-Base.repo CentOS-AppStream.repo CentOS-Extras.repo
- sed -i 's/#baseurl=/baseurl=/g' CentOS-Base.repo CentOS-AppStream.repo CentOS-Extras.repo
- sed -i 's/http:\/\/mirror.centos.org/https:\/\/mirrors.aliyun.com/g' CentOS-Base.repo CentOS-AppStream.repo CentOS-Extras.repo
3、之后运行yum clean all 清空缓存,运行yum makecache生成缓存
- yum clean all
- yum makecache