How to Configure a Local Repository on RHEL 8

Reading Time: 3 minutes

How to Configure a Local Repository on RHEL 8 shows an alternative to using local repositories instead of using Internet repositories provided by the Red Hat Network.

We’ve written an article explaining how to create an HTTP server to use as a network install server for RHEL. We’ll need this HTTP server to create a local repository. So, check this article first:
https://dpcvirtualtips.com/creating-a-network-install-server-on-rhel-8/

In this case, for instance, our RHEL 8 has a subscription enabled to download packages from the Red Hat Network. We can confirm it by executing the following command:

subscription-manager config --list

So, let’s provide the step-by-step procedure to use a local repository instead of using the Red Hat Network:

1- Firstly, we need to disable the Red Hat Network. Doing it, our system will not use the Red Hat Network repositories anymore:

subscription-manager config --rhsm.manage_repos=0

2- Inspect the repository list:

dnf repolist

As we can see, there are no repositories available – this is the expected behavior after disabling the Red Hat Network repositories:

3- In our case, we’re adding a manual entry on /etc/hosts to reach the HTTP server by its hostname or FQDN:

echo "192.168.255.161   rhel8-install.lab.local   rhel8-install" >> /etc/hosts
ping -c 2 rhel8-install.lab.local

4- Test the HTTP server connectivity from the client system:

curl http://rhel8-install.lab.local

You should have something like it – indicating that the HTTP server is available and working as expected:

5- Create a new repository file to specify the local repositories – the file must have the “.repo” extension:

touch /etc/yum.repos.d/local.repo

And add the following content:

[MyLocalRepo_BaseOS]
name=MyLocalRepo BaseOS
baseurl=http://rhel8-install.lab.local/BaseOS
enabled=1
gpgcheck=0

[MyLocalRepo_AppStream]
name=MyLocalRepo AppStream
baseurl=http://rhel8-install.lab.local/AppStream
enabled=1
gpgcheck=0

6- Inspect the system’s repositories:

dnf repolist

As we can see, the system is using the new repos now:

7- Install a package to test. In this case, for instance, let’s install the “nmap” package:

dnf install nmap -y

The “nmap” package was installed using the local repo:

That’s it for now 🙂