Print Friendly, PDF & Email

 
REQUEST

I want to set up a local yum repository with packages I downloaded manually.

 
RELATED

 
SOLUTION

There is a tool called createrepo which simplifies the task at hand. Just install it and run with specifying a directory with downloaded packages.

 
TESTCASE

If you already have a configured repository, then install createrepo package by

[root@dbpilot ~] yum install createrepo -y

Or if your host is in a restricted network (no internet, no yum repository) you can download it manually on another host as described in DOWNLOADING A PACKAGE WITHOUT INSTALLING IT and then transfer it to your host. Use localinstall option to install manually downloaded packages.

[root@dbpilot ~] pwd
/oracle/packages

[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

[root@dbpilot ~] yum localinstall createrepo-0.9.9-26.el7.noarch.rpm deltarpm-3.6-3.el7.x86_64.rpm python-deltarpm-3.6-3.el7.x86_64.rpm

Verify that createrepo is installed

[root@dbpilot ~] rpm -qa |grep createrepo
createrepo-0.9.9-26.el7.noarch

Copy all packages that you want to have in your repository into one directory. For this testcase I have 5 packages

[root@dbpilot ~] pwd
/oracle/packages
[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

Change to that directory and run the following command

[root@dbpilot ~] cd /oracle/packages
[root@dbpilot ~] createrepo --database /oracle/packages
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

After the command is completed, a new repodata directory is created. It contains necessary metadata and sqlite database for 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. A name of the file can be anything you want but should be ended with .repo

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

Place the following into the local.repo file

[MyLocalRepository]
name=My local repository 
baseurl=file:///oracle/packages
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:///oracle/packages - The location of your packages.
enabled=1                       - Enabling repository

For more details about repository parameters refer to man pages

[root@dbpilot ~] man yum.conf

Now the yum repository is ready for use

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

[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


[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.

[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.

 
 

Version  : 11:39 06.02.2018
Platform : RHEL5-RHEL7