How to Configure an Offline YUM Repository in Linux

Setting up an offline YUM repository in Linux allows you to manage packages without internet connectivity. This guide covers configuring an offline YUM repository for RHEL 9 and Oracle Linux. Follow these steps to create and use a local repository with ISO files or DVDs.

1. Insert the DVD or Mount the ISO File

Insert the RHEL 9 installation DVD or mount the ISO file on your server. For virtual machines, go to the VM settings, navigate to Storage, and select the ISO file.

Offline YUM repository setup

2. Mount the RHEL 9 ISO File / Installation DVD

Create a directory to mount the ISO file:

[root@dbdocs ~]# mkdir -p /media/cdrom

Mount the ISO file:

[root@dbdocs ~]# mount /dev/sr0 /media/cdrom

[root@dbdocs ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               4.0M     0  4.0M   0% /dev
tmpfs                  890M     0  890M   0% /dev/shm
tmpfs                  356M  5.7M  351M   2% /run
/dev/mapper/rhel-root   17G  7.0G   11G  41% /
/dev/sda1             1014M  292M  723M  29% /boot
tmpfs                  178M  108K  178M   1% /run/user/1000
/dev/sr0               9.0G  9.0G     0 100% /media/cdrom
tmpfs                  178M   36K  178M   1% /run/user/0
[root@dbdocs ~]#

Alternatively, if the ISO file is on disk:

mount -o loop rhel-9.2-x86_64-dvd.iso /media/cdrom/

3. Configure the Repository by Setting Up the .repo File

Copy the media.repo file from the mounted directory:

[root@dbdocs yum.repos.d]# cp /media/cdrom/media.repo /etc/yum.repos.d/

Rename and set permissions for the file:

[root@dbdocs yum.repos.d]# mv media.repo redhat9.2.repo
[root@dbdocs yum.repos.d]# chmod 644 redhat9.2.repo

Edit the redhat9.2.repo file with the following configuration:

[root@dbdocs yum.repos.d]# vi /etc/yum.repos.d/redhat9.2.repo
[InstallMedia]
name=Red Hat Enterprise Linux 9.2.0
mediaid=None
metadata_expire=-1
gpgcheck=1
cost=500
enabled=1
baseurl=file:///media/cdrom/BaseOS/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[InstallMedia-AppStream]
name=Red Hat Enterprise Linux 9.2.0 - AppStream
metadata_expire=-1
gpgcheck=1
enabled=1
baseurl=file:///media/cdrom/AppStream/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

4. Clean Yum/DNF and Subscription Manager Cache

Clear the cache to ensure Yum/DNF operates correctly:

[root@dbdocs yum.repos.d]# dnf clean all
8 files removed

5. Verify Whether Yum/DNF is Successfully Retrieving Packages

Check if packages are being retrieved from the local repository:

[root@dbdocs yum.repos.d]# dnf repolist
repo id                                                                   repo name
InstallMedia                                                              Red Hat Enterprise Linux 9.2.0
InstallMedia-AppStream                                                    Red Hat Enterprise Linux 9.2.0 - AppStream

[root@dbdocs yum.repos.d]# yum repolist
repo id                                                                   repo name
InstallMedia                                                              Red Hat Enterprise Linux 9.2.0
InstallMedia-AppStream                                                    Red Hat Enterprise Linux 9.2.0 - AppStream

6. Install Packages Using the DNF/Yum Package Manager

To install a package, such as make, use the following command:

-- To check if the package is installed
[root@dbdocs yum.repos.d]# yum list installed make
Error: No matching Packages to list

-- To install the package
[root@dbdocs yum.repos.d]# yum install make

This will confirm that the local YUM/DNF repository is working correctly.



Rate Your Experience

: 89 : 1


Last updated in November, 2024

Online Tests
Read more

Cloud Technology
Read more

Oracle Database
Read more

MSSQL Database
Read more

PostGres Database
Read more

Linux
Read more

ASP/C#
Read more

Quick Access