In environments with limited or no internet access—like secure datacenters or air-gapped systems—managing software packages can be a hassle. That’s where setting up a local YUM repository on your RHEL machine becomes incredibly handy.
In this guide, I’ll walk you through the step-by-step process to set up your own local repository server for RHEL 8 and RHEL 9 using httpd
(Apache) and createrepo
.
Let’s dive in! 🏊♂️
1: Download Necessary Packages on a Machine with Internet
Before we begin, you’ll need access to a machine that can connect to the internet, just once.
On that machine:
mkdir -p ~/offline-repo-packages
cd ~/offline-repo-packages
# Download createrepo and httpd with their dependencies
yumdownloader --resolve createrepo httpd
This downloads the RPM packages and their dependencies to your local folder.
2: Move Packages to Your Repo Server
Once downloaded:
- Upload the
.rpm
files to an external SFTP server. - From your internal RHEL server (which doesn’t have internet access), download them to a local folder.
3: Install Required Tools on the Repo Server
Now on the RHEL machine where you’ll host the local repo:
sudo yum install *.rpm
This installs httpd
(Apache web server) and createrepo
which we’ll use to generate repository metadata.
4: Create Directory Structure
We’ll separate the repo based on OS versions—RHEL 8 and RHEL 9:
sudo -u apache mkdir -p /var/www/html/repo/rhel8
sudo -u apache mkdir -p /var/www/html/repo/rhel9
Move the relevant .rpm
files into each folder based on the version.
5: Create Repo Metadata
Use createrepo
to generate metadata for each folder:
sudo -u apache createrepo /var/www/html/repo/rhel8
sudo -u apache createrepo /var/www/html/repo/rhel9
📝 Tip: Run this command every time you add or remove packages from the repo folders.
6: Configure Apache to Serve the Repo
Edit your Apache config file (usually found at /etc/httpd/conf/httpd.conf
) to look like this:
ServerRoot "/etc/httpd"
Listen 80
Listen 8001 #for custom Port
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost
DocumentRoot "/var/www/html"
<Directory />
AllowOverride none
Require all denied
</Directory>
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
TypesConfig /etc/mime.types
AddDefaultCharset UTF-8
<IfModule mime_magic_module>
MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
LogLevel warn
IncludeOptional conf.d/*.conf
Then, start and enable the Apache server:
sudo systemctl enable --now httpd
7: Create the YUM Repo Config File
Let’s now configure the local repo client-side so yum
knows about it.
First, remove any existing .repo
files (optional but ensures a clean slate):
sudo rm -r /etc/yum.repos.d/
sudo mkdir -p /etc/yum.repos.d/
Then create a new file:
sudo vim /etc/yum.repos.d/local.repo
Add the following content based on your RHEL version:
For RHEL 8:
[local-repo]
name=Local RHEL8 Repository
baseurl=http://<your-server-ip>:port/repo/rhel8
enabled=1
gpgcheck=0
For RHEL 9:
[local-repo]
name=Local RHEL9 Repository
baseurl=http://<your-server-ip>:port/repo/rhel9
enabled=1
gpgcheck=0
Replace <your-server-ip>:port
with the IP address and port of your repo server.
8: Test the Local Repo
Run the following to make sure the repo is working:
sudo yum repolist
You should see local-repo
listed.
To see available packages:
sudo yum list available
This will only show packages that are not currently installed on the system.
🛠️ Troubleshooting & Tips
-
Permissions: Make sure the repo folders are owned by the
apache
user and have775
permissions:sudo chown -R apache:apache /var/www/html/repo/ sudo chmod -R 775 /var/www/html/repo/
-
Test with curl:
curl -vk http://<your-server-ip>/repo/rhel8/repodata/repomd.xml
This should return metadata XML without error.
-
Metadata Refresh: After adding new RPMs, always re-run:
sudo -u apache createrepo /var/www/html/repo/rhel8
Final Thoughts
Setting up a local YUM repo can save time, bandwidth, and headaches—especially in environments where you need tight control over packages or no external internet access is allowed.
It’s a great tool in the sysadmin or DevOps toolkit and also teaches a lot about how Linux package management works under the hood.