Repository Management
Applies to CentOS Stream 9 & 10 / AlmaLinux 9.x & 10.x / Rocky Linux 9.x & 10.x
Software repositories are the sources from which DNF obtains packages. Properly managing repositories is a fundamental system administration skill — you need to know which repositories are configured on your system, how to add new ones, and how to control repository priority.
What You Will Learn
Section titled “What You Will Learn”- View and manage configured repositories
- Enable and disable repositories
- Add third-party repositories
- The structure of
.repofiles - Configure repository priorities
- Use
dnf config-manager
Prerequisites
Section titled “Prerequisites”- A system with EL 9.x / 10.x installed
- A user account with
sudoprivileges - The system is connected to the internet
- Familiarity with DNF Basics
Viewing Repositories
Section titled “Viewing Repositories”List Enabled Repositories
Section titled “List Enabled Repositories”$ dnf repolistExample output:
repo id repo nameappstream AlmaLinux 9 - AppStreambaseos AlmaLinux 9 - BaseOSextras AlmaLinux 9 - ExtrasList All Repositories (Including Disabled)
Section titled “List All Repositories (Including Disabled)”$ dnf repolist allExample output:
repo id repo name statusappstream AlmaLinux 9 - AppStream enabledappstream-debug AlmaLinux 9 - AppStream - Debug disabledappstream-source AlmaLinux 9 - AppStream - Source disabledbaseos AlmaLinux 9 - BaseOS enabledbaseos-debug AlmaLinux 9 - BaseOS - Debug disabledbaseos-source AlmaLinux 9 - BaseOS - Source disabledcrb AlmaLinux 9 - CRB disabledextras AlmaLinux 9 - Extras enabledView Repository Details
Section titled “View Repository Details”$ dnf repoinfo baseosExample output:
Repo-id : baseosRepo-name : AlmaLinux 9 - BaseOSRepo-status : enabledRepo-revision : 1711234567Repo-updated : Mon 24 Mar 2026 08:00:00 AM CSTRepo-pkgs : 1,842Repo-available-pkgs: 1,842Repo-size : 1.5 GRepo-baseurl : https://repo.almalinux.org/almalinux/9/BaseOS/x86_64/os/Repo-expire : 86,400 second(s) (last: Mon 24 Mar 2026 10:15:00 AM CST)Repo-filename : /etc/yum.repos.d/almalinux-baseos.repo.repo File Structure
Section titled “.repo File Structure”All repository configuration files are stored in the /etc/yum.repos.d/ directory with a .repo extension.
$ ls /etc/yum.repos.d/A typical .repo file looks like this:
[baseos]name=AlmaLinux $releasever - BaseOSbaseurl=https://repo.almalinux.org/almalinux/$releasever/BaseOS/$basearch/os/enabled=1gpgcheck=1countme=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-AlmaLinux-9metadata_expire=86400Field descriptions:
| Field | Description |
|---|---|
[baseos] | Repository ID, a unique identifier |
name | Repository name, used for display purposes only |
baseurl | The URL of the repository |
mirrorlist | Mirror list URL (use either this or baseurl) |
enabled | 1 to enable, 0 to disable |
gpgcheck | 1 to enable GPG signature verification, 0 to disable |
gpgkey | Path to the GPG public key |
metadata_expire | Metadata expiration time (in seconds) |
priority | Repository priority (requires dnf-plugins-core) |
Enabling and Disabling Repositories
Section titled “Enabling and Disabling Repositories”Using dnf config-manager
Section titled “Using dnf config-manager”Both EL 9 and EL 10 use DNF 4 (EL 10 ships 4.20), so the config-manager syntax is the same:
$ sudo dnf config-manager --set-disabled crb$ sudo dnf config-manager --set-enabled crb$ dnf repolist | grep crbcrb AlmaLinux 9 - CRBTemporarily Enabling/Disabling Repositories
Section titled “Temporarily Enabling/Disabling Repositories”If you only want to use a repository for a single operation without modifying the configuration:
$ sudo dnf install --enablerepo=crb some-devel-package$ sudo dnf update --disablerepo=epelAdding Third-Party Repositories
Section titled “Adding Third-Party Repositories”Method 1: Install a Repository RPM Package
Section titled “Method 1: Install a Repository RPM Package”Most well-known third-party repositories provide RPM packages that automatically configure the repository:
$ sudo dnf install epel-releaseThis will automatically create the corresponding .repo file under /etc/yum.repos.d/ and import the GPG key.
Method 2: Use dnf config-manager
Section titled “Method 2: Use dnf config-manager”$ sudo dnf config-manager --add-repo https://example.com/repo/el9/example.repoThis downloads the remote .repo file to /etc/yum.repos.d/.
Method 3: Manually Create a .repo File
Section titled “Method 3: Manually Create a .repo File”-
Create the
.repofileCreate a custom repository configuration $ sudo vi /etc/yum.repos.d/my-custom.repoEnter the following content:
[my-custom-repo]name=My Custom Repositorybaseurl=https://repo.example.com/el9/$basearch/enabled=1gpgcheck=1gpgkey=https://repo.example.com/RPM-GPG-KEY-example -
Refresh the cache
Clear and rebuild the cache $ sudo dnf clean all$ sudo dnf makecache -
Verify the repository is active
Confirm the new repository appears in the list $ dnf repolist
Repository Priority
Section titled “Repository Priority”When multiple repositories provide packages with the same name, you can use priorities to control which repository DNF prefers.
-
Ensure
dnf-plugins-coreis installedInstall the DNF plugin package $ sudo dnf install -y dnf-plugins-core -
Edit the repository configuration file and add the
priorityfieldEdit the repository file $ sudo vi /etc/yum.repos.d/epel.repoAdd the following under the
[epel]section:priority=10
Priority rules:
- Lower numbers mean higher priority
- The default priority is
99 - It is recommended to keep official repositories at the default or a high priority, and set third-party repositories to a lower priority
| Repository | Recommended Priority |
|---|---|
| baseos / appstream | 10 (default is fine) |
| EPEL | 20 |
| Other third-party repositories | 30 or higher |
dnf config-manager Command Summary
Section titled “dnf config-manager Command Summary”EL 9 and EL 10 (DNF 4.20) use the same syntax:
$ dnf config-manager --dump baseos$ sudo dnf config-manager --save --setopt=epel.priority=20$ sudo dnf config-manager --add-repo https://example.com/repo.repo$ sudo dnf config-manager --set-enabled <repo-id>$ sudo dnf config-manager --set-disabled <repo-id>Common Issues
Section titled “Common Issues””Cannot find a valid baseurl for repo”
Section titled “”Cannot find a valid baseurl for repo””This is typically a network issue or an invalid repository URL:
$ curl -I https://repo.almalinux.org/$ dig mirrorlist.centos.orgIf using a server in China, you may need to switch to a domestic mirror.
Using Domestic Mirrors (China)
Section titled “Using Domestic Mirrors (China)”Using Alibaba Cloud mirrors as an example, edit the corresponding .repo file and replace the baseurl with the Alibaba Cloud address:
$ sudo cp /etc/yum.repos.d/almalinux-baseos.repo /etc/yum.repos.d/almalinux-baseos.repo.bak”GPG check FAILED”
Section titled “”GPG check FAILED””The repository’s GPG key may not have been imported:
$ sudo rpm --import https://repo.example.com/RPM-GPG-KEY-example$ rpm -qa gpg-pubkey*Further Reading
Section titled “Further Reading”- DNF Package Management Basics — Everyday package management operations
- EPEL and Third-Party Repositories — Install and use EPEL
- RPM Basics — Low-level package management tool
man dnf.conf— Detailed DNF configuration file referenceman yum.conf— Repository configuration file format reference