配置CentOS 8的yum/dnf源可以提高软件包下载速度和稳定性。以下是步骤:
1.备份原有仓库
在修改前,首先进行仓库备份,以便于回滚操作。
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
2.清空原有仓库
清空原有仓库的所有内容。
sudo echo "" > /etc/yum.repos.d/CentOS-Base.repo
3.配置阿里云源
编辑CentOS-Base.repo,输入以下内容保存。
sudo vi /etc/yum.repos.d/CentOS-Base.repo
[BaseOS]
name=CentOS-$releasever - Base - aliyun
baseurl=https://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[updates]
name=CentOS-$releasever - Updates - aliyun
baseurl=https://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[extras]
name=CentOS-$releasever - Extras - aliyun
baseurl=https://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
4.再次备份仓库
再次备份阿里云源的repo。
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.aliyun
以上操作后,重启yum/dnf即可使用阿里云源,例如:
sudo dnf upgrade
另外,以下为清华大学的CentOS8源示例:
- CentOS 8 BaseOS
[BaseOS]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Official
- CentOS 8 AppStream
[AppStream]
name=CentOS-$releasever - AppStream
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/AppStream/$basearch/os/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Official
注意:以上示例为各仓库的基本配置,如需添加其他第三方源请自行搜索。
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:CentOS8 yum/dnf 配置国内源的方法 - Python技术站