RHEL: Create a local RPM repository

# Tested on RHEL/CentOS 6 & 7

# Mount the installation disk and copy packages from <cdrom>/Packages to a local directory.
# I'll use /depot as local repository.


# Once done, first of all, you have to install createrepo package:

cd /depot

ll *createrepo*
   -r--r--r--. 1 root root 93764 Jan 17 01:45 createrepo-0.9.9-23.el7.noarch.rpm

rpm -ihv createrepo-0.9.9-23.el7.noarch.rpm
   warning: createrepo-0.9.9-23.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
   error: Failed dependencies:
           deltarpm is needed by createrepo-0.9.9-23.el7.noarch
           libxml2-python is needed by createrepo-0.9.9-23.el7.noarch
           python-deltarpm is needed by createrepo-0.9.9-23.el7.noarch

rpm -ihv createrepo-0.9.9-23.el7.noarch.rpm deltarpm-3.6-3.el7.x86_64.rpm \
         libxml2-python-2.9.1-5.el7_1.2.x86_64.rpm python-deltarpm-3.6-3.el7.x86_64.rpm
   warning: createrepo-0.9.9-23.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
   Preparing...                          ################################# [100%]
   Updating / installing...
      1:deltarpm-3.6-3.el7               ################################# [ 25%]
      2:python-deltarpm-3.6-3.el7        ################################# [ 50%]
      3:libxml2-python-2.9.1-5.el7_1.2   ################################# [ 75%]
      4:createrepo-0.9.9-23.el7          ################################# [100%]



# Next, while being under /depot, run following command in order to create the repository:

createrepo .
   Spawning worker 0 with 3705 pkgs
   Workers Finished
   Saving Primary metadata
   Saving file lists metadata
   Saving other metadata
   Generating sqlite DBs
   Sqlite DBs complete



# Now that you have a repo setup, "yum" needs to know about it. Create a file named
# <my_local_depot>.repo under /etc/yum.repos.d directory with following content:

vi /etc/yum.repos.d/my_local_depot
   [my_local_depot]
   name=my_local_depot
   baseurl=file:///depot/
   enabled=1
   gpgcheck=1
   gpgkey=file:///etc/pki/rpm-gpg/<RPM-GPG-KEY-CentOS-7>

# * Note: If GPG key is not defined in yum.repos.d file, you'll have to import a valid key,
#   usually under /etc/pki/rpm-gpg, before trying to install any package, otherwise you'll
#   have a message similar to this one:
#
# You have enabled checking of packages via GPG keys. This is a good thing.
# However, you do not have any GPG public keys installed. You need to download
# the keys for packages you wish to install and install them.
# You can do that by running the command:
# rpm --import public.gpg.key
#
# Alternatively you can specify the url to the key you would like to use
# for a repository in the 'gpgkey' option in a repository section and yum
# will install it for you.
#
# For more information contact your distribution or package provider.
# The Project GPG keys are included in the centos-release package, and are typically
# found in /etc/pki/rpm-gpg



# To import a GPG key do this:

find / -name "*RPM-GPG*"
   /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Testing-7
   /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
   /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Debug-7

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7



# To test, run a "yum" command. It should be pulling information about packages from the
# local repository (for practical reasons, I've disabled all other default repositories
# by renaming /etc/yum.repos.d/*.repo files to /etc/yum.repos.d/*.repo.orig):

cd /etc/yum.repos.d/

ll
   total 32
   -rw-r--r--. 1 root root 1664 Dec  9 10:59 CentOS-Base.repo.orig
   -rw-r--r--. 1 root root 1309 Dec  9 10:59 CentOS-CR.repo.orig
   -rw-r--r--. 1 root root  649 Dec  9 10:59 CentOS-Debuginfo.repo.orig
   -rw-r--r--. 1 root root  290 Dec  9 10:59 CentOS-fasttrack.repo.orig
   -rw-r--r--. 1 root root  630 Dec  9 10:59 CentOS-Media.repo.orig
   -rw-r--r--. 1 root root 1331 Dec  9 10:59 CentOS-Sources.repo.orig
   -rw-r--r--. 1 root root 1952 Dec  9 10:59 CentOS-Vault.repo.orig
   -rw-r--r--. 1 root root   81 Jan 17 02:10 my_local_depot.repo


yum list mlocate
   Loaded plugins: fastestmirror
   my_local_depot                                                                            | 2.9 kB  00:00:00
   my_local_depot/primary_db                                                                 | 2.8 MB  00:00:00
   Loading mirror speeds from cached hostfile
   Available Packages
   mlocate.x86_64                                      0.26-5.el7                                     my_local_depot      <---



# Now, packages are found on (and can be installed from) local repository

yum install mlocate

   Loaded plugins: fastestmirror
   Loading mirror speeds from cached hostfile
   Resolving Dependencies
   --> Running transaction check
   ---> Package mlocate.x86_64 0:0.26-5.el7 will be installed
   --> Finished Dependency Resolution

   Dependencies Resolved

   ==================================================================================
    Package               Arch          Version          Repository             Size
   ==================================================================================
   Installing:
    mlocate               x86_64        0.26-5.el7       my_local_depot        112 k   <---

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

   Total download size: 112 k
   Installed size: 378 k
   Is this ok [y/d/N]: y
   Downloading packages:
   Running transaction check
   Running transaction test
   Transaction test succeeded
   Running transaction
   Warning: RPMDB altered outside of yum.
     Installing : mlocate-0.26-5.el7.x86_64                                                                                                                                                        1/1
     Verifying  : mlocate-0.26-5.el7.x86_64                                                                                                                                                        1/1

   Installed:
     mlocate.x86_64 0:0.26-5.el7

   Complete!

0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
Moving SSL Certificate from IIS to Apache
Viewed 1509 times since Mon, Feb 18, 2019
CentOS / RHEL : How to move a Volume Group from one system to another
Viewed 2803 times since Mon, Jan 28, 2019
RHEL: Back-up/Replicate a partition table
Viewed 2883 times since Sun, May 27, 2018
A Simple Guide to Oracle Cluster File System (OCFS2) using iSCSI on Oracle Cloud Infrastructure
Viewed 7437 times since Sat, Jun 2, 2018
Expand or grow a file system on a Linux VMWare VM without downtime
Viewed 11233 times since Fri, Jul 27, 2018
20 Linux Command Tips and Tricks That Will Save You A Lot of Time linux
Viewed 4150 times since Thu, Apr 18, 2019
RHCS6: ’fencing’ basics
Viewed 1900 times since Sun, Jun 3, 2018
30 Handy Bash Shell Aliases For Linux / Unix / MacOS
Viewed 3525 times since Thu, Feb 11, 2021
Linux Audit The Linux security blog about Auditing, Hardening, and Compliance lynis
Viewed 1594 times since Thu, Jan 16, 2020
Linux RedHat How To Create An RPM Package
Viewed 2347 times since Sun, Jan 9, 2022