How to Configure YUM Repositories in CentOS/RHEL 7 and 8

Enabling RedHat Software Repositories

Registering a system to the subscription management service automatically configures access to software repositories based on the attached subscriptions. To view all available repositories:

[user@host ~]$ yum repolist all
Loaded plugins: langpacks

repo id                                    repo name                                        status
rhel-8-server-debug-rpms/8Server/x86_64    Red Hat Enterprise Linux 8 Server (Debug RPMs)   disabled
rhel-8-server-rpms/8Server/x86_64          Red Hat Enterprise Linux 8 Server (RPMs)         enabled: 5,071
rhel-8-server-source-rpms/8Server/x86_64   Red Hat Enterprise Linux 8 Server (Source RPMs)  disabled
repolist: 5,071

The yum-config-manager command can be used to enable or disable repositories. To enable a repository, the command sets the enabled parameter to 1. For example, the following command enables the rhel-8-server-debug-rpms repository:

[user@host ~]$ yum-config-manager --enable rhel-8-server-debug-rpms
Loaded plugins: langpacks
===================== repo: rhel-8-server-debug-rpms ======================
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/8Server
baseurl =
cache = 0
cachedir = /var/cache/yum/x86_64/8Server/rhel-8-server-debug-rpms
check_config_file_age = True
cost = 1000
deltarpm_percentage =
enabled = 1
...output omitted...

Non-Red Hat sources provide software through third-party repositories, which can be accessed by the yum command from a website, FTP server, or the local file system. For example, Adobe provides some of its software for Linux through a Yum repository. In a Red Hat classroom, the classroom server hosts Yum repositories.

To enable support for a new third-party repository, create a file in the /etc/yum.repos.d/ directory. Repository configuration files must end with a .repo extension. The repository definition contains the URL of the repository, a name, whether to use GPG to check the package signatures and if so, the URL pointing to the trusted GPG key.

Creating Yum Repositories

Create Yum repositories with the yum-config-manager command. The following command creates a file named /etc/yum.repos.d/dl.fedoraproject.org_pub_epel_8_x86_64_.repo with the output shown:

[user@host ~]$ yum-config-manager --add-repo=""
Loaded plugins: langpacks
adding repo from:

name=added from: baseurl=

Modify this file to provide customized values and location of a GPG key. Keys are stored in various locations on the remote repository site, such as, Administrators should download the key to a local file rather than allowing yum to retrieve the key from an external source. For example:

name=EPEL 8

RPM Configuration Packages for Local Repositories

Some repositories provide a configuration file and GPG public key as part of an RPM package that can be downloaded and installed using the yum localinstall command. For example, the volunteer project called Extra Packages for Enterprise Linux (EPEL) provides software not supported by Red Hat but compatible with Red Hat Enterprise Linux

The following command installs the Red Hat Enterprise Linux 8 EPEL repo package:

[user@host ~]$ rpm --import
[user@host ~]$ yum install

Configuration files often list multiple repository references in a single file. Each repository reference begins with a single-word name in square brackets.

[user@host ~]$ cat /etc/yum.repos.d/epel.repo
name=Extra Packages for Enterprise Linux 8 - $basearch
#baseurl=$basearch mirrorlist=$basearch

name=Extra Packages for Enterprise Linux 8 - $basearch - Debug #baseurl=$basearch/debug mirrorlist=

name=Extra Packages for Enterprise Linux 8 - $basearch - Source #baseurl=

To define a repository, but not search it by default, insert the enabled=0 parameter. Repositories can be enabled and disabled persistently with yum-config-manager command or temporarily with yum command options, –enablerepo=PATTERN and –disablerepo=PATTERN.