第三方仓库怎么加:EPEL、CRB、Remi(Rocky 9 实测)
什么时候该用它
Section titled “什么时候该用它”系统仓库里没有你要的包(htop、glibc-static、新版 PHP),需要加第三方源。顺序很重要:EPEL 先装,Remi 依赖 EPEL;CRB 不是「第三方」,是 Rocky 自带但默认关闭的构建依赖源。
顺序:EPEL → CRB → Remi
Section titled “顺序:EPEL → CRB → Remi”- EPEL:
dnf install epel-release,包来自 extras,装完启用epel与epel-cisco-openh264; - CRB:默认不启用,按需
--enablerepo=crb,不用永久开; - Remi:先有 EPEL,再装
remi-release,装完启用remi-safe与remi-modular。
EPEL:装完多了两个源
Section titled “EPEL:装完多了两个源”sudo dnf install -y epel-releasednf repolist --enabledrepo id repo nameappstream Rocky Linux 9 - AppStreambaseos Rocky Linux 9 - BaseOSepel Extra Packages for Enterprise Linux 9 - aarch64epel-cisco-openh264 Extra Packages for Enterprise Linux 9 openh264 (From Cisco) - aarch64extras Rocky Linux 9 - Extras装完就能拿到 EPEL 里的包,例如:
dnf list available htophtop.aarch64 3.3.0-1.el9 epelCRB:默认关闭,按需临时开
Section titled “CRB:默认关闭,按需临时开”sudo dnf install -y glibc-staticsudo dnf install -y --enablerepo=crb glibc-staticrpm -q glibc-staticError: Unable to find a match: glibc-static ← 不开 CRB...glibc-static-2.34-283.el9_8.aarch64 ← 开了 CRB 才装得上CRB(CodeReady Builder)放的是开发/构建依赖(*-devel、glibc-static 这类)。用完不用关——--enablerepo 只作用于那一条命令。
Remi:先 EPEL,再装仓库包
Section titled “Remi:先 EPEL,再装仓库包”sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpmdnf repolist --enabled | grep -i remiremi-modular Remi's Modular repository for Enterprise Linux 9 - aarch64remi-safe Safe Remi's RPM repository for Enterprise Linux 9 - aarch64Remi 用于较新的 PHP/Redis 等。它的 PHP 版本通过模块流选择(remi-modular),装之前先 dnf module list php 看清可用流。
冲突矩阵:同一个包被多个源提供
Section titled “冲突矩阵:同一个包被多个源提供”| 包 | 可能来源 | 建议 |
|---|---|---|
htop、tmux 等工具 | epel | 直接用,冲突少 |
glibc-static、*-devel | crb | 用 --enablerepo=crb 临时开 |
php、redis | remi-modular / 系统模块 | 先 dnf module list,只用一种来源 |
nginx | appstream / nginx 官方源 | 二选一,别混装 |
规则只有一条:同一个包只让一个源提供。出现 --enablerepo 后版本变了、或 dnf update 要把系统包换成第三方版本,就说明两个源在抢同一个包。
- 永久启用第三方源:
enabled=1的第三方源会参与dnf update,可能替换系统包;优先临时--enablerepo; - 跳过 EPEL 直接装 Remi:
remi-release的依赖会解析失败或留下半配置; - GPG key 没导入:第三方源首次安装会校验 key,交互式确认在脚本里会卡住,用
--nogpgcheck之前先想清楚风险。
练习:只为一个包临时启用 CRB
Section titled “练习:只为一个包临时启用 CRB”前置:Rocky 9,root 或 sudo。
sudo dnf install -y glibc-static # 预期失败sudo dnf install -y --enablerepo=crb glibc-staticrpm -q glibc-staticdnf repolist --enabled | grep -c crb # 预期 0:CRB 没有被永久启用检查:
- 第一条命令报
Unable to find a match - 第二条成功,
rpm -q有版本号 - 第三条输出
0,证明--enablerepo没有改永久配置
- 多仓库冲突的三种手段:多仓库冲突
- 自建仓库:离线环境装包
- 包名与事务回滚:dnf history undo