06 Feb 2014, 09:30

Local Yum Repository for CentOS/RHEL/Fedora

If you use a Fedora/CentOS/RHEL system, have some RPMs to install, you may want to have your own repo instead of using the rpm command.

You will need to get the createrepo package :

yum install -y createrepo

Put your packages in /opt/packages/myapp :

# createrepo /opt/packages/myapp
Spawning worker 0 with 865 pkgs
Workers Finished
Gathering worker results

Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

Then, create a /etc/yum.repos.d/myapp.repo


As I don't sign my packages nor have the key for external packages, I set gpgcheck=0

Then do as usual :

 yum update

Then you can use :

yum install <package>

Bonus, if you want to have a local copy of an external repository (one you can't get on your LAN), you can use reposync in the yum-utils package :

On another VM which have access to the repo (in my example remi one, which provides latests version of PHP/MySQL for RHEL/CentOS/Fedora) :

As you have in /etc/yum.repos.d/remi.repo :

name=Les RPM de remi pour Enterprise Linux 6 - $basearch

name=Les RPM de remi de PHP 5.5 pour Enterprise Linux 6 - $basearch
# WARNING: If you enable this repository, you must also enable "remi"


what is important is to use the name inside the brackets :

reposync -n -r remi
reposync -n -r remi-php55

It will create a remi and remi-php55 directories in which you will have the latest RPMs for each repo ; then copy these directories to your target server and create your local repo as mentionned above and you're done ; if you plan to do this on a wider basis, you may consider something like SpaceWalk to build a central and internal yum repository.