帮助中心

这里有最新的使用文档和教程

< 返回

将Centos的yum源更换为国内的阿里云源

2024-01-02 23:30 作者:31IDC 阅读量:255 所属分类:Linux系统

1、备份系统本身的yum源文件

  1. 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

  1. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo


CentOS 6 (如果不可用,请拉到最底部使用新方法)

  1. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

由于各大镜像站(阿里、163、清华等)都不再维护 CentOS 6 的 Yum 源镜像,当前找到如下办法:
直接编辑 /etc/yum.repos.d/Centos-Base.repo ,清空所有内容,替换如下代码:

  1. vi /etc/yum.repos.d/Centos-Base.repo
  1. [base]
  2. name=CentOS-6
  3. failovermethod=priority
  4. baseurl=https://vault.centos.org/6.9/os/x86_64/
  5. gpgcheck=0




CentOS 7

  1. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo



CentOS 8

进入yum.repos.d目录

  1. cd /etc/yum.repos.d




备份3个源文件

  1. cp CentOS-Base.repo CentOS-Base.repo.bak
  1. cp CentOS-AppStream.repo CentOS-AppStream.repo.bak
  1. cp CentOS-Extras.repo CentOS-Extras.repo.bak



修改3个文件中的地址:

  1. sed -i 's/mirrorlist=/#mirrorlist=/g' CentOS-Base.repo CentOS-AppStream.repo CentOS-Extras.repo
  1. sed -i 's/#baseurl=/baseurl=/g' CentOS-Base.repo CentOS-AppStream.repo CentOS-Extras.repo
  1. sed -i 's/http:\/\/mirror.centos.org/https:\/\/mirrors.aliyun.com/g' CentOS-Base.repo CentOS-AppStream.repo CentOS-Extras.repo




3、之后运行yum clean all 清空缓存,运行yum makecache生成缓存

  1. yum clean all
  2. yum makecache

31IDC - 12 年深耕海外 IDC 高端资源