DEV Community

Cover image for Host a Local RPM Package Repository on Red Hat Linux
shamain anjum
shamain anjum

Posted on

Host a Local RPM Package Repository on Red Hat Linux

Today’s project was both interesting and very RHCSA-relevant: creating a private local RPM repository on Red Hat Linux.

This is a must-have skill for organizations managing many systems that rely on custom or internally built RPM packages.

🔧 Objective

  • Create a local repository of RPM packages
  • Host it over Apache HTTP
  • Configure client systems to use the repo via a .repo file
  • Verify package installation from the local repository

📚 RHCSA Skills Covered

✔ Software installation with dnf and rpm

✔ Web server management (httpd)

✔ Repository creation and configuration

✔ SELinux and firewall troubleshooting

✔ Service enablement and verification

1️⃣ Install Required Packages

On the server:
sudo dnf install -y httpd createrepo

Image description

Start and enable Apache:

sudo systemctl enable --now httpd

2️⃣ Create a Repository Directory
sudo mkdir -p /var/www/html/rpms

Copy or download some RPM packages:
sudo cp /path/to/*.rpm /var/www/html/rpms/

3️⃣ Initialize the Repository
sudo createrepo /var/www/html/rpms/
This creates the metadata necessary for clients to use the repo.

Image description

4️⃣ Configure Firewall and SELinux

Allow HTTP access:

sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --reload

Image description

Apply SELinux context:
sudo restorecon -Rv /var/www/html/

Check your repo in browser or via curl:
curl http://localhost/rpms/
You should see a list of RPM files.

Image description

5️⃣ Create Client .repo File On any Red Hat client:

sudo nano /etc/yum.repos.d/localrepo.repo

Example content:
[localrepo]
name=My Local RPM Repo
baseurl=http:///rpms/
enabled=1
gpgcheck=0

6️⃣ Test the Repository

sudo dnf clean all
sudo dnf repolist

Install any RPM from the repo:

sudo dnf install

🧪 Try It Yourself

  • Add more packages to /var/www/html/rpms/ and run createrepo again
  • Test with gpgcheck=1 and a custom GPG key
  • Move your repo to an NFS share and try hosting it
  • Write a script to automate repository updates

✅ Recap
| Task | Tool/Command |
| --------------------------------- | ------------------------------------------ |
| Install required tools | dnf install httpd createrepo |
| Copy RPM packages | cp *.rpm /var/www/html/rpms/ |
| Create repo metadata | createrepo /var/www/html/rpms/ |
| Enable firewall + restore SELinux | firewalld, restorecon |
| Configure client repo | Create .repo file in /etc/yum.repos.d/ |

🎯 Why This Matters (RHCSA)

RHCSA tests your ability to:

  • Manage packages with rpm and dnf
  • Configure and troubleshoot repositories
  • Manage services and SELinux in real-world setups
  • This project touched all of these core competencies.

Top comments (0)