一个计算机技术爱好者与学习者

0%

好好学Linux:CentOS更换软件安装源

1. 前言

之前整理过《好好学Linux:Ubuntu/Debian更换软件安装源》,Ubuntu/Debian中更换国内软件安装源,可以加快软件的安装速度。

同样的,在CentOS中更换国内软件安装源,也能加快软件安装速度。

2. 备用国内源

其他软件源参考《开源镜像站》

3. CentOS7更换软件安装源(已废弃)

1、备份原安装源

1
cp /etc/yum.repos.d/CentOS-Base.repo{,.bak}

2、下载国内的安装源

1
2
3
4
5
wget http://mirrors.aliyun.com/repo/Centos-7.repo
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
# wget http://mirrors.aliyun.com/repo/Centos-7.repo
# wget http://mirrors.cloud.tencent.com/repo/centos7_base.repo
mv Centos-7.repo /etc/yum.repos.d/Centos-Base.repo

3、更新软件安装源

1
2
yum clean all
yum makecache

yum makecache可能会报错:

1
Could not resolve host: mirrorlist.centos.org; Unknown error

解决办法:

1
curl -fsSL https://autoinstall.plesk.com/PSA_18.0.62/examiners/repository_check.sh | bash -s -- update >/dev/null

参考文档:Plesk or system updates fail on CentOS 7: Could not resolve host: mirrorlist.centos.org

4. CentOS7更新软件安装源(推荐)

1
2
3
4
sed -i.bak  \
-e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org/centos|baseurl=https://mirrors.ustc.edu.cn/centos-vault/centos|g' \
/etc/yum.repos.d/CentOS-Base.repo

5. CentOS8更换软件安装源

CentOS8已于2021年12月31日停止维护,在2022年1月31日,CentOS团队终于从官方镜像中移除CentOS8的所有包。

如果仍然需要运行CentOS8,我们可以在 /etc/yum.repos.d 中更新安装源为阿里云的镜像源。

1、备份原安装源

1
cp -r /etc/yum.repos.d{,.bak}

2、替换安装源

1
2
3
rm /etc/yum.repos.d/*.repo -rf
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
#curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo

3、更新软件安装源

1
2
yum clean all
yum makecache