> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Configuring Repositories

> Explains DNF repository management on RHEL 10 including system registration, viewing and configuring .repo files, enabling or disabling repos, creating custom repositories, and installing packages.

In this lesson you will learn how DNF uses repositories on Red Hat Enterprise Linux 10 (RHEL 10), how to view and manage repository configuration, and how to create and use a custom repository. Most software on RHEL 10 is distributed as RPM packages and managed with DNF.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/pGYwDVd7uFSlinOw/images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/Installing-Software/Configuring-Repositories/rhel-10-software-management-rpm.jpg?fit=max&auto=format&n=pGYwDVd7uFSlinOw&q=85&s=a9343acaad35c6b5a6c13c707ed768be" alt="A dark presentation slide titled &#x22;Software Management on RHEL 10&#x22; showing two rounded boxes: one labeled &#x22;RHEL 10&#x22; with a server icon and an arrow pointing to another labeled &#x22;RPM&#x22; with a package icon." width="1920" height="1080" data-path="images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/Installing-Software/Configuring-Repositories/rhel-10-software-management-rpm.jpg" />
</Frame>

Historically administrators used YUM on older Red Hat releases; on modern systems like RHEL 10, DNF is the standard package manager. DNF installs, updates, removes, and searches packages — but it relies on repositories to locate those packages.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/pGYwDVd7uFSlinOw/images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/Installing-Software/Configuring-Repositories/yum-to-dnf-rhel-migration.jpg?fit=max&auto=format&n=pGYwDVd7uFSlinOw&q=85&s=4da134e419b9de11372aba71620eaf2a" alt="A dark presentation slide titled &#x22;From YUM to DNF&#x22; showing a left panel for legacy YUM (used on older RHEL releases) and a right panel for DNF (standard today, the tool to use on RHEL 10). A blue arrow between the panels indicates the migration from YUM to DNF." width="1920" height="1080" data-path="images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/Installing-Software/Configuring-Repositories/yum-to-dnf-rhel-migration.jpg" />
</Frame>

What DNF does:

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/pGYwDVd7uFSlinOw/images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/Installing-Software/Configuring-Repositories/dnf-install-update-remove-search.jpg?fit=max&auto=format&n=pGYwDVd7uFSlinOw&q=85&s=884ed5bde008ad88f64abf34fd68bf47" alt="A dark slide titled &#x22;What DNF Does and Where It Looks&#x22; showing four outlined panels with icons and labels: Install, Update, Remove, and Search. Each panel contains a simple teal icon representing the respective action." width="1920" height="1080" data-path="images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/Installing-Software/Configuring-Repositories/dnf-install-update-remove-search.jpg" />
</Frame>

Because RHEL is subscription-based, systems must be registered with Red Hat to access the official Red Hat repositories. If a system is not registered, package operations such as install or update can fail.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/pGYwDVd7uFSlinOw/images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/Installing-Software/Configuring-Repositories/register-with-red-hat-official-repos.jpg?fit=max&auto=format&n=pGYwDVd7uFSlinOw&q=85&s=2de351a5d1b26d379ee9b54ba17dd52f" alt="A dark-themed infographic slide that says &#x22;Register First, Then You Get Access&#x22; and highlights &#x22;Register the system with Red Hat&#x22; inside a rounded box with a key icon. A downward arrow points toward another box labeled &#x22;Official Repositories.&#x22;" width="1920" height="1080" data-path="images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/Installing-Software/Configuring-Repositories/register-with-red-hat-official-repos.jpg" />
</Frame>

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/pGYwDVd7uFSlinOw/images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/Installing-Software/Configuring-Repositories/system-not-registered-install-update-fails.jpg?fit=max&auto=format&n=pGYwDVd7uFSlinOw&q=85&s=be8bb44a28256cfba60601560ad0827c" alt="A dark-themed infographic titled &#x22;Not Registered? Expect Errors&#x22; showing a boxed warning &#x22;System not registered&#x22; with arrows pointing to two panels labeled &#x22;Install fails&#x22; and &#x22;Update fails.&#x22;" width="1920" height="1080" data-path="images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/Installing-Software/Configuring-Repositories/system-not-registered-install-update-fails.jpg" />
</Frame>

Register your system with subscription-manager and attach an appropriate subscription using your Red Hat account credentials:

```bash theme={null}
sudo subscription-manager register --username your-redhat-username --password your-redhat-password
sudo subscription-manager attach --auto
```

<Callout icon="lightbulb" color="#1CB2FE">
  Registering is required to access Red Hat's official repositories. Without it, DNF cannot retrieve packages from those repositories.
</Callout>

## Repository basics

A repository (repo) is a location that stores RPM packages and metadata. Repositories can be:

* Official Red Hat repositories (requires subscription/registration).
* Third-party repositories (e.g., Docker, vendor repos).
* Internal/private repositories hosted inside your organization.

DNF reads repository definitions from files in `/etc/yum.repos.d/` (files ending in `.repo`) or from files managed by `subscription-manager` (e.g. `/etc/yum.repos.d/redhat.repo`).

## Common repository commands

* List enabled repositories:

```bash theme={null}
sudo dnf repolist
```

* List enabled repositories with detailed info including base URL:

```bash theme={null}
sudo dnf repolist -v
```

* List all repositories, including disabled ones:

```bash theme={null}
sudo dnf repolist --all
```

* Enable/disable repositories with subscription-manager:

```bash theme={null}
sudo subscription-manager repos --enable=<repo-id>
sudo subscription-manager repos --disable=<repo-id>
```

* Toggle repositories without editing files using dnf config-manager (provided by `dnf-plugins-core`):

```bash theme={null}
sudo dnf install -y dnf-plugins-core
sudo dnf config-manager --set-enabled <repo-id>
sudo dnf config-manager --set-disabled <repo-id>
```

## Understanding `.repo` files

Repo definitions use a simple INI-style format. Files belong in `/etc/yum.repos.d/` and must end with `.repo`. A repository stanza looks like:

* `[repo-id]` — short identifier (required)
* `name` — human-friendly name (recommended)
* `baseurl` — URL or local path where packages/metadata are stored
* `enabled` — `1` (enabled) or `0` (disabled)
* `gpgcheck` — `1` to verify package signatures (recommended)
* `gpgkey` — URL or file path to the signing key

Use the table below for a quick reference:

| Field | Description | Example |
| - | - | - |
| `repo id` / `[repo-id]` | Repository short identifier (used when enabling/disabling) | `[docker-ce-stable]` |
| `name` | Human readable repository name | `Docker CE Stable - $basearch` |
| `baseurl` | Where to find packages and metadata | `https://download.docker.com/linux/rhel/$releasever/$basearch/stable` |
| `enabled` | Enable (1) or disable (0) the repo | `enabled=1` |
| `gpgcheck` | Verify GPG signatures (1 = enabled) | `gpgcheck=1` |
| `gpgkey` | Location of GPG public key | `gpgkey=https://download.docker.com/linux/rhel/gpg` |

Example `.repo` file (Docker CE):

```ini theme={null}
# /etc/yum.repos.d/docker-ce.repo
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://download.docker.com/linux/rhel/$releasever/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://download.docker.com/linux/rhel/gpg
```

Knowing how `.repo` files work is useful even if you primarily use `subscription-manager` or `dnf config-manager`.

## Demo: create and use a custom repository

The following demo shows how to add a custom repo file, refresh metadata, inspect available packages, and install a package from that repository. Use caution when mixing repositories from different distributions or major releases.

<Callout icon="warning" color="#FFCC00">
  Mixing repositories from a different distribution or a different major release (for example, adding Rocky Linux 9 repositories to a RHEL 10 system) can cause dependency conflicts and break package resolution. Use such cross-distro repositories only for isolated testing. Also, setting gpgcheck=0 disables package signature verification and is insecure for production; prefer gpgcheck=1 with a valid gpgkey.
</Callout>

1. Create a new repo file:

```bash theme={null}
sudo vim /etc/yum.repos.d/rocky.repo
```

Add the following contents (example pointing to Rocky Linux 9 BaseOS):

```ini theme={null}
[rocky-baseos]
name=Rocky Linux BaseOS
baseurl=https://download.rockylinux.org/pub/rocky/9/BaseOS/x86_64/os/
enabled=1
gpgcheck=0
```

2. Refresh DNF metadata and cache:

```bash theme={null}
sudo dnf clean all
sudo dnf makecache
```

During `makecache` DNF downloads repository metadata for enabled repositories — you should see the metadata for `rocky-baseos` if the `baseurl` is reachable.

3. Verify the repository is active:

```bash theme={null}
sudo dnf repolist
```

Example truncated output might include:

```text theme={null}
repo id                                repo name
rhel-10-for-x86_64-appstream-rpms      Red Hat Enterprise Linux 10 for x86_64 - AppStream (RPMs)
rhel-10-for-x86_64-baseos-rpms         Red Hat Enterprise Linux 10 for x86_64 - BaseOS (RPMs)
rocky-baseos                           Rocky Linux BaseOS
```

4. List available packages from the new repository:

```bash theme={null}
sudo dnf list --repo rocky-baseos
```

Sample package list (truncated):

```text theme={null}
tmux.x86_64                         3.2a-5.el9           rocky-baseos
tuned-profiles-cpu-partitioning.noarch 2.26.0-1.el9      rocky-baseos
tzdata.noarch                       2026a-1.el9_7        rocky-baseos
zsh.x86_64                          5.8-9.el9            rocky-baseos
zstd.x86_64                         1.5.5-1.el9          rocky-baseos
```

5. Install a package from the repository:

```bash theme={null}
sudo dnf install zsh
```

You should see a transaction summary and download progress. Example (truncated):

```text theme={null}
Transaction Summary
=========================================================================================================
Install  1 Package

Total download size: 3.4 M
Installed size: 7.9 M
Is this ok [y/N]: y
Downloading Packages:
zsh-5.9-15.el10.x86_64.rpm                                                   2.7 MB/s | 3.4 MB     00:01
...
Installed:
  zsh-5.9-15.el10.x86_64
Complete!
```

## Notes on repository versions and priorities

* Package versions and release tags (e.g., `.el9`, `.el10`) will vary depending on repository origin. Mixing repos from different major releases can introduce incompatible packages.
* Consider repository priorities or modular filtering if you need to control which repo provides a package on systems with many enabled repositories. RHEL provides tooling and best practices to manage this in production.

## Toggling a repository quickly

You can enable or disable repositories without editing files using `dnf config-manager`:

```bash theme={null}
sudo dnf config-manager --disable rocky-baseos
sudo dnf repolist   # verify it's disabled

sudo dnf config-manager --enable rocky-baseos
sudo dnf repolist   # verify it's enabled
```

## Summary

After this lesson you should be able to:

* Register a system to access Red Hat repositories.
* List repositories and inspect repository metadata.
* Enable or disable repositories via `subscription-manager` or `dnf config-manager`.
* Create a `.repo` file manually and refresh repository metadata.
* List packages in a specific repository and install packages from it.

## Links and references

* Red Hat Subscription Manager: [https://access.redhat.com/documentation/en-us/red\_hat\_subscription\_management/](https://access.redhat.com/documentation/en-us/red_hat_subscription_management/)
* DNF documentation: [https://dnf.readthedocs.io/](https://dnf.readthedocs.io/)
* RHEL package and repository concepts: [https://access.redhat.com/documentation/en-us/red\_hat\_enterprise\_linux/](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/)
* dnf-plugins-core (provides `config-manager`): install via `sudo dnf install -y dnf-plugins-core`

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/red-hat-certified-system-administrator-rhcsa/module/a16261b2-a01f-4d77-8123-ca2fe5359edd/lesson/6342b5fd-20a1-44bf-ab25-bbd568c98018" />

  <Card title="Practice Lab" icon="flask-conical" cta="Learn more" href="https://learn.kodekloud.com/user/courses/red-hat-certified-system-administrator-rhcsa/module/a16261b2-a01f-4d77-8123-ca2fe5359edd/lesson/1635360d-9141-4720-a89e-7b5811155166" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.