CentOS 添加 EPEL 源指南

EPEL(Extra Packages for Enterprise Linux)是一个为 CentOS、Red Hat Enterprise Linux(RHEL)以及其他基于这些发行版的 Linux 系统提供额外软件包的第三方仓库,通过添加 EPEL 源,我们可以方便地获取到更多软件包,丰富我们的系统功能,本文将详细介绍如何在 CentOS 系统中添加 EPEL 源。
添加 EPEL 源
使用 yum 命令添加 EPEL 源
(1)打开终端。
(2)执行以下命令:
sudo yum install epel-release
(3)等待安装完成。
手动添加 EPEL 源
(1)打开终端。
(2)使用文本编辑器(如 vi、gedit 等)打开 /etc/yum.repos.d/epel.repo 文件。

(3)在文件中添加以下内容:
[epel]
name=Extra Packages for Enterprise Linux 7 - x86_64
baseurl=https://download.fedoraproject.org/pub/epel/7/x86_64/
enabled=1
gpgcheck=1
gpgkey=https://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7
(4)保存并关闭文件。
(5)执行以下命令刷新 yum 缓存:
sudo yum clean all
sudo yum makecache
验证 EPEL 源是否添加成功
查看 EPEL 源列表
执行以下命令查看 EPEL 源列表:
sudo yum repolist enabled
如果列表中包含 EPEL 源,则表示 EPEL 源已添加成功。
安装 EPEL 源中的软件包
尝试安装一个 EPEL 源中的软件包,

sudo yum install nginx
如果安装成功,则表示 EPEL 源已添加成功。
FAQs
Q1:如何删除 EPEL 源?
A1:打开 /etc/yum.repos.d/epel.repo 文件,将其中的 [epel] 部分删除,然后保存并关闭文件,接着执行以下命令刷新 yum 缓存:
sudo yum clean all
sudo yum makecache
Q2:为什么我的 CentOS 系统没有 EPEL 源?
A2:可能是因为你的 CentOS 系统版本不支持 EPEL 源,EPEL 主要支持 CentOS 6、CentOS 7 和 CentOS 8,你可以通过查看系统版本来确认是否支持 EPEL 源,如果系统版本不支持,可以考虑升级到支持 EPEL 源的版本。