- 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 (如果不可用,請(qǐng)拉到最底部使用新方法)
- wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
直接編輯 /etc/yum.repos.d/Centos-Base.repo ,清空所有內(nèi)容,替換如下代碼:
- 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
進(jìn)入yum.repos.d目錄
- cd /etc/yum.repos.d
備份3個(gè)源文件
- 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個(gè)文件中的地址:
- 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、之后運(yùn)行yum clean all 清空緩存,運(yùn)行yum makecache生成緩存
- yum clean all
- yum makecache