Skip to content

How to Make a Local Yum Repository

  • Yum

Sometimes, the Linux servers does not have any internet connection in the environment, thus yum command has no way to resolve dependencies among being installed packages through repositories on the internet, such as Oracle public yum repository.

In such situation, you have 2 options.

  • You may ask the system administrator to enable the server the ability to connect internet, just temporarily.
  • You can create a local repository for yum, which don't need any internet connection, to resolve the complex dependencies.

In this post, we design some steps to make a local repository for yum to resolve dependencies.

Mount Linux ISO

Before we can use the original Linux ISO to make the repository, we have to mount it to the file system.

[root@test ~]# mkdir -p /mnt/disc
[root@test ~]# mount -o loop /path_to_source/rhel-server-7.6-x86_64-dvd.iso /mnt/disc
mount: /dev/loop0 is write-protected, mounting read-only

Add Local Repo

We copy the repo file in the media to yum directory.

[root@test ~]# cp /mnt/disc/media.repo /etc/yum.repos.d/

Then we make the file writable.

[root@test ~]# chmod 644 /etc/yum.repos.d/media.repo

Edit the repo file. Here we set gpgcheck into 1 and append the last 3 lines.

[root@test ~]# vi /etc/yum.repos.d/media.repo
[InstallMedia]
name=Red Hat Enterprise Linux 7.6
mediaid=1539194970.388895
metadata_expire=-1
gpgcheck=1
cost=500
enabled=1
baseurl=file:///mnt/disc/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

The ID of the repository is InstallMedia.

Enable Local Repo

We clear all yum cache.

[root@test ~]# yum clean all
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
              : manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Cleaning repos: InstallMedia

We list all enabled yum repositories, which makes yum refresh itself.

[root@test ~]# yum repolist enabled
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
              : manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
InstallMedia                                             | 4.3 kB     00:00
(1/2): InstallMedia/group_gz                               | 146 kB   00:00
(2/2): InstallMedia/primary_db                             | 4.2 MB   00:00
repo id                      repo name                                    status
InstallMedia                 Red Hat Enterprise Linux 7.6                 5,152
repolist: 5,152

As we can see, the new repository InstallMedia is enabled.

Install Packages

Now we can install a lot of packages at the same time. For example, preparing RPMs for Oracle database 19c.

[root@test ~]# yum -y install bc binutils compat-libcap1 compat-libstdc++-33 glibc glibc-devel ksh libX11 libXau libXi libXrender libXrender-devel libXtst libaio libaio-devel libgcc libstdc++ libstdc++-devel libxcb make net-tools nfs-utils smartmontools sysstat
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
              : manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Package bc-1.06.95-13.el7.x86_64 already installed and latest version
Package binutils-2.27-34.base.el7.x86_64 already installed and latest version
Package compat-libcap1-1.10-7.el7.x86_64 already installed and latest version
No package compat-libstdc++-33 available.
Package glibc-2.17-260.el7.x86_64 already installed and latest version
Package glibc-devel-2.17-260.el7.x86_64 already installed and latest version
Package libX11-1.6.5-2.el7.x86_64 already installed and latest version
Package libXau-1.0.8-2.1.el7.x86_64 already installed and latest version
Package libXi-1.7.9-1.el7.x86_64 already installed and latest version
Package libXrender-0.9.10-1.el7.x86_64 already installed and latest version
Package libXtst-1.2.3-1.el7.x86_64 already installed and latest version
Package libaio-0.3.109-13.el7.x86_64 already installed and latest version
Package libgcc-4.8.5-36.el7.x86_64 already installed and latest version
Package libstdc++-4.8.5-36.el7.x86_64 already installed and latest version
Package libstdc++-devel-4.8.5-36.el7.x86_64 already installed and latest version
Package libxcb-1.13-1.el7.x86_64 already installed and latest version
Package 1:make-3.82-23.el7.x86_64 already installed and latest version
Package net-tools-2.0-0.24.20131004git.el7.x86_64 already installed and latest version
Package 1:nfs-utils-1.3.0-0.61.el7.x86_64 already installed and latest version
Package 1:smartmontools-6.5-1.el7.x86_64 already installed and latest version
Package sysstat-10.1.5-17.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package ksh.x86_64 0:20120801-139.el7 will be installed
---> Package libXrender-devel.x86_64 0:0.9.10-1.el7 will be installed
---> Package libaio-devel.x86_64 0:0.3.109-13.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package              Arch       Version                 Repository        Size
================================================================================
Installing:
ksh                  x86_64     20120801-139.el7        InstallMedia     885 k
libXrender-devel     x86_64     0.9.10-1.el7            InstallMedia      17 k
libaio-devel         x86_64     0.3.109-13.el7          InstallMedia      13 k

Transaction Summary
================================================================================
Install  3 Packages

Total download size: 915 k
Installed size: 3.2 M
Downloading packages:
warning: /mnt/disc/Packages/ksh-20120801-139.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Public key for ksh-20120801-139.el7.x86_64.rpm is not installed
--------------------------------------------------------------------------------
Total                                               85 MB/s | 915 kB  00:00
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
Importing GPG key 0xFD431D51:
Userid     : "Red Hat, Inc. (release key 2) <[email protected]>"
Fingerprint: 567e 347a d004 4ade 55ba 8a5f 199e 2f91 fd43 1d51
Package    : redhat-release-server-7.6-4.el7.x86_64 (@anaconda/7.6)
From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
Importing GPG key 0x2FA658E0:
Userid     : "Red Hat, Inc. (auxiliary key) <[email protected]>"
Fingerprint: 43a6 e49c 4a38 f4be 9abf 2a53 4568 9c88 2fa6 58e0
Package    : redhat-release-server-7.6-4.el7.x86_64 (@anaconda/7.6)
From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libaio-devel-0.3.109-13.el7.x86_64                           1/3
  Installing : libXrender-devel-0.9.10-1.el7.x86_64                         2/3
  Installing : ksh-20120801-139.el7.x86_64                                  3/3
InstallMedia/productid                                   | 1.6 kB     00:00
  Verifying  : ksh-20120801-139.el7.x86_64                                  1/3
  Verifying  : libXrender-devel-0.9.10-1.el7.x86_64                         2/3
  Verifying  : libaio-devel-0.3.109-13.el7.x86_64                           3/3

Installed:
  ksh.x86_64 0:20120801-139.el7         libXrender-devel.x86_64 0:0.9.10-1.el7
  libaio-devel.x86_64 0:0.3.109-13.el7

Complete!

Since there's no compat-libstdc++-33 package in the media, you need to get it from outside then install it. It's another story of course.

Leave a Reply

Your email address will not be published. Required fields are marked *