跳转到内容

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 (Extra Packages for Enterprise Linux) 是由 Fedora 社区维护的附加软件仓库。它为 RHEL/EL 系统提供官方仓库中没有的高质量软件包。

EPEL 的特点:

  • 可靠:由 Fedora 项目官方维护,质量有保障
  • 丰富:提供数千个额外的软件包
  • 安全:所有包都经过 GPG 签名验证
  • 兼容:不会替换官方仓库中的包,只作为补充

常见的 EPEL 独有软件包包括:htopneofetchcertbotfail2banansible 等。

  1. 启用 CRB 仓库

    EPEL 中的许多包依赖 CRB (CodeReady Builder) 仓库中的开发库,建议先启用它:

    启用 CRB 仓库
    $ sudo dnf config-manager --set-enabled crb
  2. 安装 EPEL

    安装 EPEL 仓库
    $ sudo dnf install -y epel-release
  3. 验证安装

    确认 EPEL 已启用
    $ dnf repolist | grep epel

    输出示例:

    epel Extra Packages for Enterprise Linux 9 - x86_64
  4. 刷新缓存

    更新元数据缓存
    $ sudo dnf makecache

安装 EPEL 后,就可以像使用官方仓库一样安装其中的软件包:

安装 EPEL 中的 htop
$ sudo dnf install htop
搜索 EPEL 中的包
$ dnf search --repo=epel fail2ban
列出 EPEL 仓库中所有可用的包
$ dnf list available --repo=epel | head -30
查看某个包来自哪个仓库
$ dnf info htop

在输出中,Repository 字段会显示 epel

如果你只想从 EPEL 安装某个包(避免从其他仓库获取):

指定仓库安装
$ sudo dnf install --repo=epel certbot

RPM Fusion 提供 Fedora 和 EL 官方仓库因许可证或专利原因无法收录的软件,如多媒体编解码器和专有驱动。

RPM Fusion 分为两个仓库:

  • free:开源但因其他原因未进入官方仓库的软件
  • nonfree:非自由/专有软件
  1. 安装 RPM Fusion free 仓库

    安装 RPM Fusion free
    $ sudo dnf install -y \
    https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-$(rpm -E %{rhel}).noarch.rpm
  2. 安装 RPM Fusion nonfree 仓库(可选)

    安装 RPM Fusion nonfree
    $ sudo dnf install -y \
    https://mirrors.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-$(rpm -E %{rhel}).noarch.rpm
  3. 验证

    确认 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 仓库由 Remi Collet 维护,主要提供最新版本的 PHP 和相关扩展,是 PHP 开发者的重要工具。

  1. 安装 Remi 仓库

    安装 Remi 仓库
    $ sudo dnf install -y \
    https://rpms.remirepo.net/enterprise/remi-release-$(rpm -E %{rhel}).rpm
  2. 查看并安装 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-opcache

    EL 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
  3. 验证

    确认 PHP 版本
    $ php -v

ELRepo 专注于硬件相关的软件包,包括内核模块、显卡驱动和其他硬件驱动。

  1. 导入 GPG 密钥

    导入 ELRepo GPG 密钥
    $ sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
  2. 安装 ELRepo

    安装 ELRepo 仓库(自动适配 EL 版本)
    $ sudo dnf install -y https://www.elrepo.org/elrepo-release-$(rpm -E %{rhel}).el$(rpm -E %{rhel}).elrepo.noarch.rpm
  3. 查看可用的内核包

    ELRepo 最常用的功能是提供最新的主线内核 (kernel-ml) 和长期支持内核 (kernel-lt):

    查看 ELRepo 中可用的内核包
    $ dnf list available --repo=elrepo-kernel

并非所有第三方仓库都值得信任。选择仓库时应考虑:

  • 维护者信誉:是否由知名个人或组织维护
  • 社区认可:是否被广泛使用和推荐
  • 更新频率:是否保持活跃更新
  • GPG 签名:是否对所有包进行签名
确认所有仓库都启用了 GPG 检查
$ grep -r "gpgcheck" /etc/yum.repos.d/ | grep "gpgcheck=0"

如果有仓库关闭了 GPG 检查,应将 gpgcheck=0 改为 gpgcheck=1

防止第三方仓库的包覆盖官方包:

为 EPEL 设置较低优先级
$ sudo dnf config-manager --save --setopt=epel.priority=20

如果你不希望第三方仓库影响某些包,可以使用 exclude 配置:

编辑 EPEL 配置,排除内核相关包
$ sudo vi /etc/yum.repos.d/epel.repo

[epel] 段添加:

exclude=kernel* kmod*
查看各仓库提供了多少已安装的包
$ dnf list installed | awk '{print $3}' | sort | uniq -c | sort -rn
查看来自特定仓库的已安装包
$ dnf list installed --repo=epel

EPEL 安装报错 “No match for argument”

Section titled “EPEL 安装报错 “No match for argument””

在某些最小化安装的系统上,可能需要先安装 epel-release 所在的仓库:

在 AlmaLinux/Rocky Linux 上
$ sudo dnf install -y epel-release

如果仍然失败,手动安装 RPM:

手动安装 EPEL RPM
$ sudo dnf install -y \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm

如果遇到包冲突:

查看包的来源仓库
$ dnf info <package-name>
使用 versionlock 锁定特定版本
$ sudo dnf install -y python3-dnf-plugin-versionlock
$ sudo dnf versionlock add <package-name>
查看已锁定的包
$ dnf versionlock list
以移除 EPEL 为例
$ sudo dnf remove epel-release
$ sudo rm -f /etc/yum.repos.d/epel*.repo
$ sudo dnf clean all

EPEL 10 是独立于 EPEL 9 的仓库,需注意以下差异:

  • 包数量较少:EPEL 10 初期收录的软件包明显少于 EPEL 9,部分常用工具可能尚未移植
  • 安装方式相同:在 EL 10 系统上运行 dnf install epel-release 会自动安装 EPEL 10
  • Remi、RPM Fusion 等第三方仓库:EL 10 支持可能滞后,使用前请确认对应版本是否已发布
在 EL 10 上安装 EPEL 10
$ sudo dnf install -y epel-release
$ dnf repolist | grep epel
# 输出应显示 "Extra Packages for Enterprise Linux 10"