How to Configure an offline YUM Repository in RHEL 9 Linux
corpline

Red Hat has recently launched its highly anticipated operating system, "RHEL 9.2" If you have installed RHEL 9 Server on your system and are looking for guidance on setting up a local yum or dnf repository using the installation DVD or ISO file, follow the steps and procedures outlined below.

1. Insert the DVD or mount the ISO file onto the server

Right-click on the VM Machine, then go to Settings. In the Settings menu, navigate to Storage. Click on the DVD icon located on the right side of the screen. Choose a disk file and select the RHEL 9 ISO file. Offline yum repository

2. Mount the RHEL 9 ISO file / Installation DVD onto the server

Create a directory to mount the ISO file on your server. For example, you can use the following command to create a directory -
 [root@dbdocs ~]# mkdir -p /media/cdrom
To mount the RHEL 9 ISO file within your RHEL 9 server, use the following mount command:
[root@dbdocs ~]# mount /dev/sr0  /media/cdrom
mount: /media/cdrom: WARNING: source write-protected, mounted read-only.
[root@dbdocs ~]# 

[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 ~]#
If you haven't mounted the ISO file in Step 1 but have already copied the RHEL 9 ISO file to your system, you can mount the file using the following command:
mount -o loop rhel-9.2-x86_64-dvd.iso /media/cdrom/

3. Configure the repository by setting up the necessary ".repo" file

Copy the media.repo file from the location where the RHEL 9 ISO file is mounted, which is typically under the /media/cdrom directory, to the /etc/yum.repos.d/ directory.
[root@dbdocs yum.repos.d]# cp /media/cdrom/media.repo /etc/yum.repos.d
Rename the media.repo file to "redhat9.2" and ensure that it has the correct permissions.
[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 as follows:
[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
Once the content is added, the rhel8.repo file should resemble the example shown above. If you have mounted the Installation DVD or ISO in a different folder, make sure to modify the location and folder name in the base URL line for both repositories. Leave the rest of the parameters unchanged.

4. Clean Yum/DNF and Subscription Manager cache to remove any unnecessary data

Use the following command to clear the cache of Yum/DNF and the Subscription Manager:
[[root@dbdocs yum.repos.d]# dnf clean all
8 files removed
[root@dbdocs yum.repos.d]#

5. Verify whether Yum/DNF is successfully retrieving packages from the local repository

Verify if the dnf repolist or yum repolist command is successfully retrieving packages from the local repositories
[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
[root@dbdocs yum.repos.d]#

6. Install packages using the DNF/Yum package manager.

Assuming that we want to install the make package, execute the following "yum" command:
--To confirm whether the package is already installed

[root@dbdocs yum.repos.d]# yum list installed make
Error: No matching Packages to list
[root@dbdocs yum.repos.d]#

--To install the package

[root@dbdocs yum.repos.d]# yum install make
Last metadata expiration check: 0:08:40 ago on Fri 09 Jun 2023 01:44:02 PM CEST.
Dependencies resolved.
========================================================================================================================================================================
 Package                             Architecture                          Version                                    Repository                                   Size
========================================================================================================================================================================
Installing:
 make                                x86_64                                1:4.3-7.el9                                InstallMedia                                542 k

Transaction Summary
========================================================================================================================================================================
Install  1 Package

Total size: 542 k
Installed size: 1.6 M
Is this ok [y/N]: y
Downloading Packages:
Red Hat Enterprise Linux 9.2.0                                                                                                          295 kB/s | 3.6 kB     00:00
Importing GPG key 0xFD431D51:
 Userid     : "Red Hat, Inc. (release key 2) "
 Fingerprint: 567E 347A D004 4ADE 55BA 8A5F 199E 2F91 FD43 1D51
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
Is this ok [y/N]: y
Key imported successfully
Importing GPG key 0x5A6340B3:
 Userid     : "Red Hat, Inc. (auxiliary key 3) "
 Fingerprint: 7E46 2425 8C40 6535 D56D 6F13 5054 E4A4 5A63 40B3
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                1/1
  Installing       : make-1:4.3-7.el9.x86_64                                                                                                                        1/1
  Running scriptlet: make-1:4.3-7.el9.x86_64                                                                                                                        1/1
  Verifying        : make-1:4.3-7.el9.x86_64                                                                                                                        1/1
Installed products updated.

Installed:
  make-1:4.3-7.el9.x86_64

Complete!
[root@dbdocs yum.repos.d]#

This confirms that the local yum/dnf repository has been successfully configured on our RHEL 9 server using the Installation DVD or ISO file.


Rate Your Experience

: 0 : 0

Online Tests
Read more

Oracle Database
Read more

MSSQL Database
Read more

PostGres Database
Read more

Linux
Read more

ASP/C#
Read more

Navigation Panel