CentOS 使用 EPEL 拓展源

Linux
203 0

简介

本教程使用的第三方镜像源:华为云、阿里云

操作步骤

1、(可选)执行以下命令,备份 epel. repo 文件

mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak
# 如果是 CentOS 8 或 RHEL 8 镜像,还需要备份 epel-modular.repo 文件。
mv /etc/yum.repos.d/epel-modular.repo /etc/yum.repos.d/epel-modular.repo.bak

如果无 epel. repo 和 epel-modular. repo 文件,请跳过本步骤

2、安装 epel-release

sudo yum install epel-release

对于 CentOS 8 或 RHEL 8 操作系统,需要更新 epel-modular. repo 文件,避免 epel. repo 文件更新失败

3、替换默认源

sudo sed -e 's!^metalink=!#metalink=!g' \
    -e 's!^#baseurl=!baseurl=!g' \
    -e 's!http://download\.fedoraproject\.org/pub/epel!https://mirrors.tuna.tsinghua.edu.cn/epel!g' \
    -e 's!http://download\.example/pub/epel!https://mirrors.tuna.tsinghua.edu.cn/epel!g' \
    -i /etc/yum.repos.d/epel*.repo

3、执行以下命令,生成缓存

yum clean metadata
yum makecache
yum install epel-release -y >/dev/null 2>&1


执行命令yum makecache后,如果回显信息为 “Another app is currently holding the yum lock”,则需执行命令rm -rf /var/run/yum.pid删除 yum.pid 文件,然后再执行命令yum makecache生成缓存。

执行命令yum makecache后,如果回显报错 “Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again”,则需执行以下命令,更新证书临时禁用 epel 源即可。

yum --disablerepo=epel -y update ca-certificates

如果使用过程中发现某些包不可用,可能是数据正在同步,请过几个小时后再重试。

示例 epel. repo

清华 CentOS 7

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch/debug
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/SRPMS
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

中科大 CentOS 7

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=https://mirrors.ustc.edu.cn/epel/7/$basearch
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=https://mirrors.ustc.edu.cn/epel/7/$basearch/debug
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=https://mirrors.ustc.edu.cn/epel/7/SRPMS
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

中科大 CentOS 8

[epel]
name=Extra Packages for Enterprise Linux $releasever - $basearch
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place it's address here.
baseurl=https://mirrors.ustc.edu.cn/epel/$releasever/Everything/$basearch
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=1
gpgcheck=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8

[epel-debuginfo]
name=Extra Packages for Enterprise Linux $releasever - $basearch - Debug
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place it's address here.
baseurl=https://mirrors.ustc.edu.cn/epel/$releasever/Everything/$basearch/debug
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux $releasever - $basearch - Source
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place it's address here.
baseurl=https://mirrors.ustc.edu.cn/epel/$releasever/Everything/SRPMS
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-source-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
gpgcheck=1
最后更新 2023-03-20
评论 ( 0 )
OωO
隐私评论