Conflicting repositories: --enablerepo, includepkgs and cost (Rocky 9, tested)
When to use it
Section titled “When to use it”dnf installs a package from a repo you did not expect, or two repos both offer the same name and you want to pin the source. On Rocky 9 there are three groups of tools: temporarily toggling repos, filtering inside a repo definition, and cost weighting. The third one did not behave as documented in this test — the page says so below.
Option one: toggle repos for one command
Section titled “Option one: toggle repos for one command”sudo dnf --disablerepo="*" --enablerepo=multi list availableAvailable Packageslibpsl.aarch64 0.21.1-5.el9 multipublicsuffix-list-dafsa.noarch 20210518-3.el9 multitree.aarch64 1.8.0-10.el9 multiwget.aarch64 1.21.1-11.el9_8 multi--disablerepo="*" turns everything off first, then --enablerepo= enables the one you trust — the most predictable approach, and it only applies to that command, so a risky repo is never left permanently enabled.
Option two: filter packages in the repo definition
Section titled “Option two: filter packages in the repo definition”[multi]name=Multibaseurl=file:///srv/multienabled=1gpgcheck=0includepkgs=treeAvailable Packagestree.aarch64 1.8.0-10.el9 multiincludepkgs=tree makes the repo expose only tree; every other package (including wget and its dependencies) becomes invisible.
The inverse uses excludepkgs:
excludepkgs=wgetAvailable Packageslibpsl.aarch64 0.21.1-5.el9 multipublicsuffix-list-dafsa.noarch 20210518-3.el9 multitree.aarch64 1.8.0-10.el9 multiwget disappears from the list; the other three remain.
Option three: cost — it did not work in this test
Section titled “Option three: cost — it did not work in this test”Two local repos provide the same rpm, with cost=10 and cost=20; repoquery --location shows which one dnf would use:
sudo dnf --disablerepo="*" --enablerepo=A,B repoquery --location treefile:///srv/repoB/tree-1.8.0-10.el9.aarch64.rpmSwapping the costs (A=99, B=1) and running again still resolved to repoB. In other words, cost did not change the selection in this scenario.
Conclusion: do not treat
costas a reliable cross-repo priority mechanism. When you must pin a source, name it with--enablerepoor exclude the unwanted source withexcludepkgs.
Common traps
Section titled “Common traps”- Permanently enabling a third-party repo (
enabled=1): a laterdnf updatemay replace system packages with third-party builds; prefer--enablerepofor one command; includepkgstakes package names, not file names: writetree, nottree-1.8.0-10.el9.aarch64;- Editing a repo file without
dnf clean all: the metadata cache still applies andlist availableappears unchanged.
Practice: install only from the repo you choose
Section titled “Practice: install only from the repo you choose”Prerequisite: Rocky 9 with a local repo built as in Offline package installs.
sudo dnf --disablerepo="*" --enablerepo=multi install -y treeChecks:
dnf --disablerepo="*" --enablerepo=multi list available | grep -c tree→ 1- Add
includepkgs=treeto/etc/yum.repos.d/multi.repo, rundnf clean all, repeat step 1 → wget no longer appears - Replace with
excludepkgs=wget(remove includepkgs) → wget is absent from the list
Next steps
Section titled “Next steps”- Building a local repo: Offline package installs
- Repos and defaults: Rocky repositories
- Rolling back a bad install: dnf history undo