How to Setup Local Yum/DNF Repository on CentOS 8 Server

Local YUM/DNF repository is the place where the rpm packages for Redhat or CentOS are stored and distributed to client servers for software installation and OS updates.
This local repository lets you save internet bandwidth as well as the time for downloading packages from the internet.
In this article, you will learn how you can locally set up a DNF or YUM repository on your CentOS 8 system using an ISO or an installation DVD.

1. Mount CentOS 8 ISO file / Installation DVD

To mount CentOS 8 ISO file inside your CentOS 8 server use the beneath mount command:

# mount CentOS-8-x86_64-1905-dvd1.iso /opt
# cd /opt
# ls

2. Create a CentOS 8 Local Yum Repository

In our case CentOS 8 Installation DVD or ISO file is mounted under /opt folder, use cp command to copy media.repo file to /etc/yum.repos.d/ directory

# cp -v /opt/media.repo  /etc/yum.repos.d/centos8.repo

Set “644” permission on “/etc/yum.repos.d/centos8.repo”

# chmod 644 /etc/yum.repos.d/centos8.repo
# ls -l /etc/yum.repos.d/centos8.repo

We need to configure the default repository file residing on the system. To check the configurations, use the cat command as shown.

# cat etc/yum.repos.d/centos8.repo

We need to modify the configuration lines using a text editor of your choice.

# nano etc/yum.repos.d/centos8.repo

Delete all the configuration, and copy & paste the configuration below.

name=CentOS Linux 8 - BaseOS

name=CentOS Linux 8 - AppStream

Save the repo file and exit the editor.

3. Clean Yum / DNF and Subscription Manager Cache

After modifying the repository file with new entries, proceed and clear the DNF / YUM cache as shown.

# dnf clean all
# yum clean all

To confirm that the system will get packages from the locally defined repositories, run the command:

# dnf repolist
# yum repolist

4. Verify whether Yum / DNF is getting packages from Local Repo

Use dnf or yum repolist command to verify whether these commands are getting packages from Local repositories or not.

# dnf repolist
# yum repolist
repo id                 repo name                                         status
InstallMedia-AppStream  CentOS Linux 8 - AppStream            4,672
InstallMedia-BaseOS     CentOS Linux 8 - BaseOS               1,658

Now set ‘enabled’ parameter from 1 to 0 in CentOS-AppStream.repo and CentOS-Base.repo files.

# nano /etc/yum/pluginconf.d/subscription-manager.conf
Save and exit the file.

5. Install Packages Using Local DNF or Yum Repository

Let’s assume we want to install nginx web server then run below dnf command:

# dnf install nginx
# yum instal nginx
dnf install nginx from local yum repository


That’s All. You have successfully configured the local yum repository on the machine.

Exit mobile version