Print Friendly, PDF & Email
You can create your own yum repository containing only the packages you need.
GOAL

Creating a custom yum repository containing required packages with all dependencies so the repository can be archived and transferred to a machine without an internet connection.

RELATED

HOW TO ENABLE PACKAGE CACHING FOR YUM
HOW TO USE YUM TO DOWNLOAD A PACKAGE WITHOUT INSTALLING IT

SOLUTION

This can be accomplished by using the createrepo software package.

DEMO

Install the createrepo package

[root@dbpilot ~] yum install createrepo -y

Copy all packages for your new repository into one directory, such as /tmp/cachedRPM

[root@dbpilot ~] pwd
/tmp/cachedRPM

[root@dbpilot ~] ls -ltr --time-style='+'
total 1380
-rw-r--r--. 1 root root   83444  deltarpm-3.6-3.el7.x86_64.rpm
-rw-r--r--. 1 root root   94168  createrepo-0.9.9-26.el7.noarch.rpm
-rw-r--r--. 1 root root   31092  python-deltarpm-3.6-3.el7.x86_64.rpm
-rw-r--r--. 1 root root  114696  mlocate-0.26-6.el7.x86_64.rpm
-rw-r--r--. 1 root root 1060508  vim-enhanced-7.4.160-1.el7.x86_64.rpm

To create the repository run

[root@dbpilot ~] createrepo --database /tmp/cachedRPM

Spawning worker 0 with 1 pkgs
Spawning worker 1 with 1 pkgs
Spawning worker 2 with 1 pkgs
Spawning worker 3 with 1 pkgs
Spawning worker 4 with 1 pkgs
Spawning worker 5 with 0 pkgs
Spawning worker 6 with 0 pkgs
Spawning worker 7 with 0 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

The repository is now ready to be consumed by yum. It contains the necessary metadata and SQLite database for the yum repository.

[root@dbpilot ~] ls -ltr --time-style='+'
total 1384
-rw-r--r--. 1 root root   83444  deltarpm-3.6-3.el7.x86_64.rpm
-rw-r--r--. 1 root root   94168  createrepo-0.9.9-26.el7.noarch.rpm
-rw-r--r--. 1 root root  114696  mlocate-0.26-6.el7.x86_64.rpm
-rw-r--r--. 1 root root   31092  python-deltarpm-3.6-3.el7.x86_64.rpm
-rw-r--r--. 1 root root 1060508  vim-enhanced-7.4.160-1.el7.x86_64.rpm
drwxr-xr-x. 2 root root    4096  repodata

Create a repository file. The name of a file can be anything you want, but it should end with .repo. For instance, the custom.repo.

[root@dbpilot ~] touch /etc/yum.repos.d/custom.repo

Place the following configuration into the created .repo file

[MyLocalRepository]
name=My local repository 
baseurl=file:///tmp/cachedRPM
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY
gpgcheck=1
enabled=1
[MyLocalRepository]             - The repository name, It can be anything you want. 
                                  No space is allowed in the name. 
                                  The brackets [] are not part of a repository name.
name=My local repository        - The comment for your repository, It can be anything you want.
baseurl=file:///tmp/cachedRPM   - The location of your packages.
enabled=1                       - To enable the cuurent repository
NOTE

For details about repository parameters refer to man pages

[root@dbpilot ~] man yum.conf

The repository is now ready to be used

####################
## Cleaning YUM cache
####################

[root@dbpilot ~] yum clean all
Loaded plugins: ulninfo
Cleaning repos: MyLocalRepository
Cleaning up everything

####################
## Getting all available repos 
####################

[root@dbpilot ~] yum repolist
Loaded plugins: ulninfo
MyLocalRepository                                                                 | 2.9 kB  00:00:00
MyLocalRepository/primary_db                                                      | 5.5 kB  00:00:00
repo id                                         repo name                                          status
MyLocalRepository                               My local repository                                5
repolist: 5

####################
## Searching for a package 
####################

[root@dbpilot ~] yum search mlocate
Loaded plugins: ulninfo
========================================= N/S matched: mlocate ==========================================
mlocate.x86_64 : An utility for finding files by name

  Name and summary matches only, use "search all" for everything.


####################
## Displaying information about a package
####################

[root@dbpilot ~] yum info mlocate
Loaded plugins: ulninfo
Available Packages
Name        : mlocate
Arch        : x86_64
Version     : 0.26
Release     : 6.el7
Size        : 112 k
Repo        : MyLocalRepository
Summary     : An utility for finding files by name
URL         : https://fedorahosted.org/mlocate/
License     : GPLv2
Description : mlocate is a locate/updatedb implementation.  It keeps a database of
            : all existing files and allows you to lookup files by name.
            :
            : The 'm' stands for "merging": updatedb reuses the existing database to avoid
            : rereading most of the file system, which makes updatedb faster and does not
            : trash the system caches as much as traditional locate implementations.
NOTE

To use created custom repository on another host, copy both the directory and the repo file to that host.

Written At
05 FEB 201814:30
Red Hat Release
5.x-7.x x64