CentOS换yum源和epel源为国内源

时间:2023-03-10 04:03:14
CentOS换yum源和epel源为国内源

CentOS换源

  • YUM源

    1. 备份原来的repo文件

      mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
    2. 在CentOS中配置使用网易或阿里的开源镜像

      网易开源镜像站

      阿里开源镜像站

      开源镜像站中有相应教程,下面使用阿里的源。

    3. 下载新的CentOS-Base.repo /etc/yum.repos.d/

      • CentOS 5

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

        或者

        curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
      • CentOS 6

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

        或者

        curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
      • CentOS 7

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

        或者

        curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    4. 之后运行

      yum clean all
      yum makecache

      生成缓存

  • EPEL源

    EPEL源在CentOS默认不存在,需要下载安装

    yum list | grep epel-release
    yum install epel-release

    安装完成后,在/etc/yum.repos.d多出如下两个文件

    epel-testing.repo epel.repo

    下载阿里开源镜像的EPEL源

    wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo

    之后运行

    yum clean all
    yum makecache

    生成缓存