How to Configure YUM Repository in RHEL 8 Linux

RHEL Linux uses online repositories to store and manage RPM packages. When you install RHEL Linux, the installation process automatically configures the necessary settings the local system needs to connect and download any required package from these repositories. But for this, you need to register the system to the RHN network and purchase an active RHEL subscription.

If your system is registered with the RHN network and you have an active RHEL subscription, you do not need to do any additional configuration or setup to install RPM packages. RHEL subscription is not free. To get it, you need to pay a subscription fee. If you want to use an RHEL system in the production environment, you should purchase it. A subscription not only allows you to download the latest and updated packages but also allows you to get technical support from Red Hat.

RedHat releases RHEL Linux under the GPL license. It means you can download and use it without purchasing a subscription. But it also means that you will not get updates and support from Red Hat. That is perfectly fine if you want to use RHEL for testing or learning in the LAB environment.

While learning and testing, you need to install several packages and dependencies. If you do not have an RHEL subscription, you cannot use the default online repositories to download and install packages. But you can create and use a local repository to install packages and dependencies.

To create a local repository, you can use the same installation disk that you used to install the Linux. If you have an RHEL ISO image file, you can also use it to create a local repository. If you are using Linux on a virtual machine, you can use the RHEL ISO image directly from the host system.

No matter what your setup is, the process for creating and using a local repository is the same.

Using virtual machines for testing and learning is the most convenient method. To learn how to RHEL Linux on virtual machines and set up RHCE/RHCSA practice lab, you can check the following tutorial.

RHCE Practice Lab Setup in VMWare and in VirtualBox

Creating and using a local YUM repository

To create a local YUM repository on RHEL/CentOS 8 and above versions, you need an RHEL/CentOS installation disk or ISO image file and at least 15GB of free disk space.

If you have an ISO image file, you can use the following commands to mount it.

# mkdir -p  /mnt/disc
# mount -o loop RHEL8.6.iso /mnt/disc


# mkdir -p  /mnt/disc
# mount /dev/sr0  /mnt/disc

If you have an RHEL installation disk, you can directly use it from /run/media/[user name]/ directory.

listing RHEL installation disk

Before RHEL8, Red Hat used to put all packages in a single directory called Packages.

listing rhel installation disk

Starting from RHEL8, Red Hat packs packages in two different directories: BaseOS and AppStream. The BaseOS directory contains all installation packages, administrative tools, and their dependencies. The AppStream directory contains all remaining packages such as Bind, LibreOffice, MariaDB, etc.

If you are creating a local repository on an earlier version, use the Packages directory in the next steps.

Create a directory under the root directory and check the available free space. If you have more than 15GB of disk space available, copy all files and directories from the installation disk to it.

#mkdir /local_repo
#df -h /local_repo
#cp -r /run/media/root/[RHEL version]/* /local_repo/
#ls -l /local_repo

The following image shows the above process.

copying all files and directory

Linux saves repository configuration files in the /etc/yum.repos.d/ directory. To create a local YUM directory, you need to create a repository configuration file in this directory. Linux treats all files having the .repo extension as repository configuration files.

Create a file having the .repo extension and add the following lines in it.



The following table explains the above settings.

[repositoryid] It is the id of the repository. It must be unique for each repository.
name It is the name of the repository.
metadata_expire It is the time in seconds after which the metadata will expire. If you set its value to -1, the metadata will never expire.
enabled It is a setting that controls the use of this repository. If you set its value to 0, Linux will not use it. If you set its value to 1, Linux will use it.
gpgcheck It is a setting that controls the GPG signature check on packages downloaded from this repository. To disable it, use the value 0. To enable it, use the value 1.
baseurl It is a URL to the directory where the yum repository's 'repodata' directory lives.
gpgkey It is a URL or a file location containing an ASCII GPG key. If you enable gpgcheck, you need to configure the path or location in this setting.

Use the cat command to verify the configuration.

local repo configuration

The yum repolist command lists the configured repositories. You can use this command to verify the recently added repositories.

listing repo

Before you use these repositories, you need to create repository data. The yum command uses the repository data to query and download packages and dependencies. The createrepo command creates repository data. By default, this command is not installed.

The yum command also offers many utilities to manage repositories. The following command installs both the createrepo command and yum utilities.

#yum install createrepo yum-utils

createrepo and yum utils

Use the createrepo command to create repository data. Specify the directory path where you copied all files and directories from the installation disk or ISO image.

#createrepo /local_repo

createrepo data

This process takes a few minutes. During this process, many cache files generate. To remove them, you can run the yum clean all command after this command.

#yum clean all

yum clean all

The createrepo command places repository data in the repodata directory. To verify the repository data, you can use the ls command.

#ls /local_repo/repodata/

listing repo data

Once the repository data is created, you can use the repositories. To verify it, you can search and install packages from it.

The following command searches the term 'semanage' in all packages.

#yum search semanage

copying all files and directory

The following command downloads the vsftpd package from the local repository and installs it.

#yum install vsftpd

installing package

That's all for this tutorial. In this tutorial, we learned how to create a local YUM repository from the RHEL installation disk or the ISO image file.

ComputerNetworkingNotes Linux Tutorials How to Configure YUM Repository in RHEL 8 Linux