CentOS 7.4 更改源指南

CentOS 7.4 是一款流行的开源操作系统,其稳定性与安全性得到了广泛的认可,默认的源地址可能会因为网络原因导致下载速度慢或者无法访问,更改源地址是一个提高系统性能和便利性的有效方法,本文将详细介绍如何在 CentOS 7.4 中更改源地址。
准备工作
在开始更改源之前,请确保您已经具备以下条件:
- 已安装 CentOS 7.4 操作系统。
- 具备基本的 Linux 命令行操作能力。
更改源地址
打开终端。
使用以下命令备份原始的源地址配置文件:
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
使用文本编辑器打开源地址配置文件:

sudo vi /etc/yum.repos.d/CentOS-Base.repo
删除文件中的所有内容,并替换为以下内容:
[base] name=CentOS base repository mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=Base&infra=$infra enabled=1 gpgcheck=1 gpgkey=http://www.centos.org/keys/RPM-GPG-KEY-CentOS-7 [epel] name=Extra Packages for Enterprise Linux mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=epel&infra=$infra enabled=1 gpgcheck=1 gpgkey=http://www.centos.org/keys/RPM-GPG-KEY-EPEL-7 [updates] name=CentOS updates repository mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=Updates&infra=$infra enabled=1 gpgcheck=1 gpgkey=http://www.centos.org/keys/RPM-GPG-KEY-CentOS-7 [addons] name=CentOS addons repository mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=addons&infra=$infra enabled=1 gpgcheck=1 gpgkey=http://www.centos.org/keys/RPM-GPG-KEY-CentOS-7 [centosplus] name=CentOS Plus repository mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=centosplus&infra=$infra enabled=1 gpgcheck=1 gpgkey=http://www.centos.org/keys/RPM-GPG-KEY-CentOS-7 [centos-testing] name=CentOS Testing repository mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=centos-testing&infra=$infra enabled=0 gpgcheck=1 gpgkey=http://www.centos.org/keys/RPM-GPG-KEY-CentOS-7
保存并关闭文件。
使用以下命令更新系统:
sudo yum clean all sudo yum makecache
验证更改
使用以下命令查看更改后的源地址:
sudo yum repolist enabled
如果看到新的源地址,则表示更改成功。
FAQs

问题:更改源后,如何查看是否生效?
解答: 您可以使用
sudo yum repolist enabled命令查看更改后的源地址是否生效。问题:更改源后,系统无法正常更新,怎么办?
解答: 检查源地址配置文件是否正确,然后尝试重新运行
sudo yum clean all和sudo yum makecache命令,如果问题依旧,可以尝试更换其他镜像源。

