One of the challenges we’ve had over the years is installing packages on RHEL and CentOS that either go away or are removed from major repos (EPEL/REMI/IUS), or, for things where we want to tie to a specific version of a package and maintain easy upgrade ability.

There are many ways to skin this cat, but, this is the way we chose. No cats were harmed in the making of this repository.


First off, you’ll need to create some directories for your repo and packages to live in. You’ll need to do this for each version and architecture you’re going to support. In this case it’s RHEL/CentOS only and versions 5 and 6.

$ mkdir -p /path/to/yum/reponame/{5,6}/{i386,x86_64}

If you had multiple architectures & OS’ you might have:


Directories are up to you really depending on what you want to store.

You’ll also need the createrepo package, and repoview if you want an HTML setup as well:

yum install createrepo repoview

We’ve got a script that’s specific to our install and as I said assumes only one architecture, but, you can tweak as you need. The advantage of the script in this format is you can run it from wherever, say you have a common shared bin directory for instance.

$ cat ./build

if (( EUID != 0 )); then
	echo "You must be root to run this command"
	exit 1

[[ -n "$1" ]] && YUMREPO="/path/to/yum/$1" || YUMREPO=$( find /path/to/yum -mindepth 1 -maxdepth 1 -type d )

for REPO in $YUMREPO; do
	REPONAME=$( basename $REPO )
	for RELEASEARCH in $( find $REPO/[0-9]* -mindepth 1 -maxdepth 1 -type d 2> /dev/null ); do
		RELEASEVER=$( basename `dirname $RELEASEARCH` )
		createrepo -d .
		repoview -f -t "$REPONAME yum repo: RHEL $RELEASEVER $BASEARCH" .

Once you’ve run it, you’ll have your repo.

Add packages & update

Now it’s built, you can add packages. Put simply, chuck an RPM in the right folder and rebuild.

Use it

Once you’ve create the repository it’s easy to then go ahead an grab a package from it.

On each server you want it to be available on, create a new repo file. We use puppet to ensure this exists where it needs to. Note that this example is only for RHEL/CentOS 6.

$ more /etc/yum.repos.d/reponame.repo

Once you’ve added that, update Yum:

$ yum clean all

Then, go ahead and search for your package. We’ll use ImageMagick as an example:

$ yum --disablerepo=* --enablerepo=reponame search package

What we’re doing in the above is ensuring only our repo responds. After this point you can install or do whatever you need to.

Orginally published at