当前位置:首页 > Linux > 正文内容

CentOS 更换源

sa2022-02-05Linux

1.备份系统原始CentOS-Base.repo文件

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 6
请参考 https://www.zhangchen.cc/?id=22 

CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

CentOS 8
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo

3.运行 yum makecache 生成缓存

4.避免出现 Couldn't resolve host 'mirrors.cloud.aliyuncs.com' ,对CentOS-Base.repo进行修改:

sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

补充:

推荐使用linux一键更换源脚本:https://supermanito.github.io/LinuxMirrors ,除了支持Centos 外还支持其他linux发行版 ,

Gitee地址:https://gitee.com/SuperManito/LinuxMirrors


[root@iZ28puny4v0Z yum.repos.d]# bash <(curl -sSL https://cdn.jsdelivr.net/gh/SuperManito/LinuxMirrors@main/ChangeMirrors.sh)
+---------------------------------------------------+
|                                                   |
|   =============================================   |
|                                                   |
|       欢迎使用 Linux 一键更换国内软件源脚本       |
|                                                   |
|   =============================================   |
|                                                   |
+---------------------------------------------------+
#####################################################
            提供以下国内软件源可供选择:
#####################################################
 ❖   阿里云              1)
 ❖   腾讯云              2)
 ❖   华为云              3)
 ❖   网易                4)
 ❖   搜狐                5)
 ❖   清华大学            6)
 ❖   浙江大学            7)
 ❖   南京大学            8)
 ❖   重庆大学            9)
 ❖   兰州大学           10)
 ❖   上海交通大学       11)
 ❖   哈尔滨工业大学     12)
 ❖   中国科学技术大学   13)
#####################################################
...

image.png


版权声明:本文由老瓦罐儿煨汤发布,如需转载请注明出处。

本文链接:https://www.zhangchen.cc/?id=19

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。