CentOS 添加 EPEL 源指南

简介
EPEL(Extra Packages for Enterprise Linux)是一个为 CentOS 等企业级 Linux 发行版提供额外软件包的项目,通过添加 EPEL 源,用户可以轻松获取更多软件包,提高系统的功能性和灵活性,本文将详细介绍如何在 CentOS 系统中添加 EPEL 源。
添加 EPEL 源
检查当前版本
在添加 EPEL 源之前,首先需要确认您的 CentOS 版本,EPEL 源对不同版本的 CentOS 支持可能有所不同。
cat /etc/redhat-release
备份原始的 yum 源文件
在添加 EPEL 源之前,建议备份原始的 yum 源文件,以防止出现问题时能够恢复。
cp /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak
下载 EPEL 源配置文件

根据您的 CentOS 版本,从以下链接下载相应的 EPEL 源配置文件:
- CentOS 7:epel-release-latest-7.noarch.rpm
- CentOS 8:epel-release-latest-8.noarch.rpm
安装 EPEL 源
使用以下命令安装 EPEL 源:
sudo rpm -Uvh epel-release-latest-7.noarch.rpm
或者对于 CentOS 8:
sudo rpm -Uvh epel-release-latest-8.noarch.rpm
验证 EPEL 源
安装完成后,使用以下命令验证 EPEL 源是否添加成功:
sudo yum repolist enabled | grep epel
输出结果应包含 EPEL 源的相关信息。
EPEL 源配置文件详解

EPEL 源配置文件通常位于 /etc/yum.repos.d/ 目录下,以下是一个 EPEL 源配置文件的示例:
[epel] name=Extra Packages for Enterprise Linux 7 - x86_64 baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/ enabled=1 gpgcheck=1 gpgkey=https://www.fedoraproject.org/static/keys/epel-release-7-0.noresign.key
name:EPEL 源的名称。baseurl:EPEL 源的镜像地址。enabled:是否启用该源,值为 1 表示启用。gpgcheck:是否启用 GPG 校验,值为 1 表示启用。gpgkey:EPEL 源的 GPG 公钥地址。
FAQs
问题:如何查看 EPEL 源中的软件包列表?
解答: 使用以下命令查看 EPEL 源中的软件包列表:
sudo yum list --enabled | grep epel
问题:如何卸载 EPEL 源?
解答: 卸载 EPEL 源需要删除相应的配置文件,首先备份原始的 yum 源文件,然后删除 EPEL 源配置文件:
sudo cp /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak sudo rm -f /etc/yum.repos.d/epel.repo

