EPEL 与第三方源
适用于 CentOS Stream 9 & 10 / AlmaLinux 9.x & 10.x / Rocky Linux 9.x & 10.x
EL 官方仓库追求稳定性,收录的软件包数量有限。EPEL 和其他第三方仓库可以大幅扩展可用软件的范围。本文介绍如何安全地使用这些仓库。
- 什么是 EPEL 以及为什么需要它
- 安装和启用 EPEL
- 其他常用第三方仓库(RPM Fusion、Remi、ELRepo)
- 安全使用第三方源的注意事项
什么是 EPEL
Section titled “什么是 EPEL”EPEL (Extra Packages for Enterprise Linux) 是由 Fedora 社区维护的附加软件仓库。它为 RHEL/EL 系统提供官方仓库中没有的高质量软件包。
EPEL 的特点:
- 可靠:由 Fedora 项目官方维护,质量有保障
- 丰富:提供数千个额外的软件包
- 安全:所有包都经过 GPG 签名验证
- 兼容:不会替换官方仓库中的包,只作为补充
常见的 EPEL 独有软件包包括:htop、neofetch、certbot、fail2ban、ansible 等。
安装 EPEL
Section titled “安装 EPEL”-
启用 CRB 仓库
EPEL 中的许多包依赖 CRB (CodeReady Builder) 仓库中的开发库,建议先启用它:
启用 CRB 仓库 $ sudo dnf config-manager --set-enabled crb -
安装 EPEL
安装 EPEL 仓库 $ sudo dnf install -y epel-release -
验证安装
确认 EPEL 已启用 $ dnf repolist | grep epel输出示例:
epel Extra Packages for Enterprise Linux 9 - x86_64 -
刷新缓存
更新元数据缓存 $ sudo dnf makecache
使用 EPEL 中的包
Section titled “使用 EPEL 中的包”安装 EPEL 后,就可以像使用官方仓库一样安装其中的软件包:
$ sudo dnf install htop$ dnf search --repo=epel fail2ban$ dnf list available --repo=epel | head -30$ dnf info htop在输出中,Repository 字段会显示 epel。
仅从 EPEL 安装
Section titled “仅从 EPEL 安装”如果你只想从 EPEL 安装某个包(避免从其他仓库获取):
$ sudo dnf install --repo=epel certbotRPM Fusion
Section titled “RPM Fusion”RPM Fusion 提供 Fedora 和 EL 官方仓库因许可证或专利原因无法收录的软件,如多媒体编解码器和专有驱动。
RPM Fusion 分为两个仓库:
- free:开源但因其他原因未进入官方仓库的软件
- nonfree:非自由/专有软件
-
安装 RPM Fusion free 仓库
安装 RPM Fusion free $ sudo dnf install -y \https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-$(rpm -E %{rhel}).noarch.rpm -
安装 RPM Fusion nonfree 仓库(可选)
安装 RPM Fusion nonfree $ sudo dnf install -y \https://mirrors.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-$(rpm -E %{rhel}).noarch.rpm -
验证
确认 RPM Fusion 仓库已添加 $ dnf repolist | grep rpmfusion输出示例:
rpmfusion-free-updates RPM Fusion for EL 9 - Free - Updates # EL 9 示例rpmfusion-nonfree-updates RPM Fusion for EL 9 - Nonfree - Updates
Remi 仓库
Section titled “Remi 仓库”Remi 仓库由 Remi Collet 维护,主要提供最新版本的 PHP 和相关扩展,是 PHP 开发者的重要工具。
-
安装 Remi 仓库
安装 Remi 仓库 $ sudo dnf install -y \https://rpms.remirepo.net/enterprise/remi-release-$(rpm -E %{rhel}).rpm -
查看并安装 PHP 版本
EL 9(使用模块化):
EL 9:列出 Remi 提供的 PHP 模块流 $ dnf module list php$ sudo dnf module reset php$ sudo dnf module enable php:remi-8.3$ sudo dnf install -y php php-cli php-fpm php-mysqlnd php-opcacheEL 10(不再分发 modular 内容,直接安装带版本号的包):
EL 10:直接安装 Remi 提供的 PHP 8.3 $ sudo dnf install -y php83 php83-php-cli php83-php-fpm php83-php-mysqlnd php83-php-opcache -
验证
确认 PHP 版本 $ php -v
ELRepo
Section titled “ELRepo”ELRepo 专注于硬件相关的软件包,包括内核模块、显卡驱动和其他硬件驱动。
-
导入 GPG 密钥
导入 ELRepo GPG 密钥 $ sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org -
安装 ELRepo
安装 ELRepo 仓库(自动适配 EL 版本) $ sudo dnf install -y https://www.elrepo.org/elrepo-release-$(rpm -E %{rhel}).el$(rpm -E %{rhel}).elrepo.noarch.rpm -
查看可用的内核包
ELRepo 最常用的功能是提供最新的主线内核 (kernel-ml) 和长期支持内核 (kernel-lt):
查看 ELRepo 中可用的内核包 $ dnf list available --repo=elrepo-kernel
安全使用第三方仓库
Section titled “安全使用第三方仓库”选择可信的仓库
Section titled “选择可信的仓库”并非所有第三方仓库都值得信任。选择仓库时应考虑:
- 维护者信誉:是否由知名个人或组织维护
- 社区认可:是否被广泛使用和推荐
- 更新频率:是否保持活跃更新
- GPG 签名:是否对所有包进行签名
始终启用 GPG 验证
Section titled “始终启用 GPG 验证”$ grep -r "gpgcheck" /etc/yum.repos.d/ | grep "gpgcheck=0"如果有仓库关闭了 GPG 检查,应将 gpgcheck=0 改为 gpgcheck=1。
使用仓库优先级
Section titled “使用仓库优先级”防止第三方仓库的包覆盖官方包:
$ sudo dnf config-manager --save --setopt=epel.priority=20如果你不希望第三方仓库影响某些包,可以使用 exclude 配置:
$ sudo vi /etc/yum.repos.d/epel.repo在 [epel] 段添加:
exclude=kernel* kmod*定期审查仓库
Section titled “定期审查仓库”$ dnf list installed | awk '{print $3}' | sort | uniq -c | sort -rn$ dnf list installed --repo=epelEPEL 安装报错 “No match for argument”
Section titled “EPEL 安装报错 “No match for argument””在某些最小化安装的系统上,可能需要先安装 epel-release 所在的仓库:
$ sudo dnf install -y epel-release如果仍然失败,手动安装 RPM:
$ sudo dnf install -y \ https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm第三方仓库包与官方仓库冲突
Section titled “第三方仓库包与官方仓库冲突”如果遇到包冲突:
$ dnf info <package-name>$ sudo dnf install -y python3-dnf-plugin-versionlock$ sudo dnf versionlock add <package-name>$ dnf versionlock list如何完全移除第三方仓库
Section titled “如何完全移除第三方仓库”$ sudo dnf remove epel-release$ sudo rm -f /etc/yum.repos.d/epel*.repo$ sudo dnf clean all- 仓库管理 — 仓库配置详解
- DNF 包管理基础 — 日常包管理操作
- RPM 基础 — 底层包管理工具
- EPEL 官方 Wiki:https://docs.fedoraproject.org/en-US/epel/
- Remi 仓库官网:https://rpms.remirepo.net/
EL 10 注意事项:EPEL 10
Section titled “EL 10 注意事项:EPEL 10”EPEL 10 是独立于 EPEL 9 的仓库,需注意以下差异:
- 包数量较少:EPEL 10 初期收录的软件包明显少于 EPEL 9,部分常用工具可能尚未移植
- 安装方式相同:在 EL 10 系统上运行
dnf install epel-release会自动安装 EPEL 10 - Remi、RPM Fusion 等第三方仓库:EL 10 支持可能滞后,使用前请确认对应版本是否已发布
$ sudo dnf install -y epel-release$ dnf repolist | grep epel# 输出应显示 "Extra Packages for Enterprise Linux 10"