Learn how to setup Local Yum Repository in RHEL 8 with our step-by-step guide. Follow detailed instructions to configure a local repository for efficient package management on your RHEL 8 system. #centlinux #linux
Table of Contents
What is a Local Yum Repository?
A Local Yum Repository is a local storage location for RPM (Red Hat Package Manager) packages and metadata used by the Yum package manager to install, update, and manage software on Red Hat-based Linux distributions like RHEL 8 (Red Hat Enterprise Linux) and CentOS. It serves as an alternative to the remote repositories provided by Red Hat or other sources on the internet.
Why Use a Local Yum Repository?
Here are several reasons why you might set up a local Yum repository:
- Offline Environments: In environments without internet access, a local repository allows you to install and update packages.
- Network Efficiency: Reduces bandwidth usage by serving packages from a local server instead of downloading them repeatedly from the internet.
- Custom Packages: Allows you to host and manage custom or third-party RPM packages that are not available in official repositories.
- Controlled Updates: Provides control over when and which packages are updated, ensuring that updates are tested before deployment.
- Internal Distribution: Facilitates the distribution of packages within an organization or to multiple servers.
How Does a Local Yum Repository Work?
A Local Yum Repository consists of:
- RPM Packages:
- The actual files that contain software and updates. These packages are the ones that will be installed or updated on your system.
- Repository Metadata:
- Information about the packages, including their versions, dependencies, and descriptions. Yum uses this metadata to resolve package dependencies and manage installations.
Components of a Local Yum Repository
- Package Directory:
- A directory where RPM packages are stored.
- Metadata Files:
- Files generated by the
createrepo
tool that include package lists, dependency information, and other data needed for package management.
- Files generated by the
- Repository Configuration:
- Configuration files that tell Yum where to find the repository and how to access it.
Recommended Online Training: Learn Bash Shell in Linux for Beginners
Problem Definition
In the latest release of Red Hat Enterprise Linux (RHEL) 8, the legacy yum (Yellowdog Updater Modifier) has been replaced by Fedora package manager i.e. dnf (Dandified yum). Although, yum command is still available for backward compatibility, but it is actually an alias that is redirecting to dnf command.
As you aware that, Red Hat Enterprise Linux (RHEL) 8 is a commercial software and we need a paid subscription to access online yum repositories to install software packages.
However, we can also configure a local yum repository of our own. So, we can conveniently install software packages on our RHEL 8 system without having a paid subscription.
In this article, we will setup Local yum Repository in RHEL 8 server.
Environment Specification
We have configured a Red hat Enterprise Linux (RHEL) 8 virtual machine with following specifications.
- CPU – 3.4 Ghz (2 cores)
- Memory – 2 GB
- Storage – 20 GB
- Hostname – rhel-8-server.example.com
- IP Address – 192.168.116.165/24
- Operating System – Red hat Enterprise Linux (RHEL) 8
Setup Local Yum Repository in RHEL 8
Copy RHEL 8 ISO file to our rhel-8-server.example.com.
# ls anaconda-ks.cfg rhel-8.0-x86_64-dvd.iso
Create a directory to mount rhel-8.0-x86_64-dvd.iso file.
# mkdir /mnt/iso
Persistently mount rhel-8.0-x86_64-dvd.iso at /mnt/iso directory.
# echo "/root/rhel-8.0-x86_64-dvd.iso /mnt/iso iso9660 defaults 0 0" >> /etc/fstab # mount -a mount: /mnt/iso: WARNING: device write-protected, mounted read-only.
In RHEL 8, the yum repository has been divided into two parts.
- BaseOS – It provides the parts of the distribution that give you a running userspace on physical hardware, a virtual machine, a cloud instance or a container.
- AppStream – It provides all the applications you might want to run in a given userspace.
Add BaseOS section for our local yum repository.
# cat > /etc/yum.repos.d/localyum.repo << EOF > [localyum_BaseOS] > name=localyum_BaseOS > baseurl=file:///mnt/iso/BaseOS > enabled=1 > gpgcheck=1 > gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release > EOF
Add AppStream section for our local yum repository.
# cat >> /etc/yum.repos.d/localyum.repo << EOF > [localyum_AppStream] > name=localyum_AppStream > baseurl=file:///mnt/iso/AppStream > enabled=1 > gpgcheck=1 > gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release > EOF
Build cache for our local yum repository.
# dnf makecache Updating Subscription Management repositories. Unable to read consumer identity This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. localyum_AppStream 13 MB/s | 5.3 MB 00:00 localyum_BaseOS 13 MB/s | 2.2 MB 00:00 Metadata cache created.
Install Apache HTTP Server using dnf command.
# dnf install -y httpd
Our local yum repository is working fine. Now, we are going to share the same local yum repository to our network RHEL 8 clients.
For this purpose, we required Apache HTTP server (that we have installed already) and a couple of amendments in configurations of our local yum repository.
Put SELinux in permissive mode, so we can mount the ISO file in /var/www/html and the same can be accessible by the network clients.
# sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/sysconfig/selinux # setenforce permissive
Enable and start Apache HTTP Service.
# systemctl enable httpd.service Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service â /usr/lib/systemd/system/httpd.service. # systemctl start httpd.service
Allow HTTP service in Linux firewall.
# firewall-cmd --permanent --add-service=http success # firewall-cmd --reload success
Create a directory in /var/www/html to mount RHEL 8 ISO.
# mkdir /var/www/html/rhel8
Edit /etc/fstab file to change the mount point of /dev/cdrom.
/root/rhel-8.0-x86_64-dvd.iso /var/www/html/rhel8 iso9660 defaults 0 0
Remount the ISO file.
# mount -a mount: /var/www/html/rhel8: WARNING: device write-protected, mounted read-only.
Edit localyum.repo file and update baseurls as follows.
[localyum_BaseOS] name=localyum_BaseOS baseurl=http://192.168.116.165/rhel8/BaseOS enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release [localyum_AppStream] name=localyum_AppStream baseurl=http://192.168.116.165/rhel8/AppStream enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
Rebuild yum cache.
# dnf clean all
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
12 files removed
# dnf makecache
Updating Subscription Management repositories.
Unable to read consumer identity This system is not registered to Red Hat Subscription Management.
You can use subscription-manager to register.
localyum_AppStream 24 MB/s | 5.3 MB 00:00
localyum_BaseOS 76 MB/s | 2.2 MB 00:00
Metadata cache created.
Check list of repositories on our RHEL 8 server.
# dnf repolist Updating Subscription Management repositories. Unable to read consumer identity This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Last metadata expiration check: 0:22:17 ago on Fri 05 Jul 2019 12:51:12 AM PKT. repo id repo name status localyum_AppStream localyum_AppStream 4,672 localyum_BaseOS localyum_BaseOS 1,658
If you are new to Linux and facing difficulty in working at Linux Bash prompt. We recommend that, you should read The Linux Command Line, 2nd Edition: A Complete Introduction by William Shotts.
Final Thoughts
If you found this guide on setting up a Local Yum Repository in RHEL 8 helpful and need further assistance with package management or other technical support, consider hiring a professional. Visit my Fiverr profile for expert services in repository management, system configuration, and more. Let’s work together to achieve your IT goals!