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
RHEL: Services basic management - systemd
Viewed 18718 times since Sat, Jun 2, 2018
Df command in Linux not updating actual diskspace, wrong data
Viewed 2895 times since Wed, May 30, 2018
LVM: Reduce an existing Logical Volume / Filesystem
Viewed 3569 times since Sat, Jun 2, 2018
How to run command or code in parallel in bash shell under Linux or Unix
Viewed 3253 times since Tue, Aug 6, 2019
Tropienie pożeracza dysku
Viewed 2283 times since Thu, May 24, 2018
How to mount software RAID1 member using mdadm
Viewed 3057 times since Wed, Oct 3, 2018
logrotate - rotates, compresses, and mails system logs.
Viewed 1755 times since Fri, Nov 30, 2018
OCFS2 Cluster File System Setup Guide in Linux
Viewed 7211 times since Sat, Jun 2, 2018
Manage SSH Key File With Passphrase
Viewed 2282 times since Tue, Mar 5, 2019
15 Linux Yum Command Examples – Install, Uninstall, Update Packages
Viewed 3398 times since Thu, Oct 25, 2018