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!