How to add packages from DVD / ISO by dnf (yum) on Linux

This guide shows how to add packages by dnf (yum) on RHEL / CentOS 8 Linux. It’s useful in offline (blocked internet access) situations.

Procedures

1. Mount DVD / ISO image

Refer the following posts and mount a DVD or ISO image of operating system installation media.

>> How to mount CD/DVD on Linux

>> How to mount ISO image on Linux

2. Create a repository file

(1) Copy media.repo in the OS media to /etc/yum.repos.d
Note: Assume that an ISO image is mounted on /media/dvdiso

cp /media/dvdiso/media.repo /etc/yum.repos.d/media.repo
chmod 644 /etc/yum.repos.d/media.repo

(2) Edit /etc/yum.repos.d/media.repo

vi /etc/yum.repos.d/media.repo

Edit and save media.repo like the following.

[InstallMedia-BaseOS]
name=InstallMedia-BaseOS
mediaid=None
meatadata_expire=1
gpgcheck=1
cost=500
baseurl=file:///media/dvdiso/BaseOS
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[InstallMedia-Appstream]
name=InstallMedia-AppStream
mediaid=None
meatadata_expire=1
gpgcheck=1
cost=500
baseurl=file:///media/dvdiso/AppStream
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

(3) Confirm the repository.

dnf repolist

If it shows like the following, the repository was edited successfully.

repo id                        repo name
InstallMedia-AppStream         InstallMedia-AppStream
InstallMedia-BaseOS            InstallMedia-BaseOS

3. Clear cache

To clear caches, run the following command.

dnf clean all

That’s about it.