Open Source

Create your own yum repository

Vincent Danen explains how to create your own yum repository with the createrepo tool. One thing it allows you to do is to distribute specialized packages within an organization.

The standard RPM package management tool in Fedora, Red Hat Enterprise Linux, and CentOS is the yum package manager. Yum works quite well, if a little bit slower than other RPM package managers like apt4rpm and urpmi, but it is solid and handles dependencies extremely well. Using it with official and third-party repositories is a breeze to set up, but what if you want to use your own repository? Perhaps you manage a large computer lab or network and need to have — or want to have — certain packages available to these systems that you maintain in-house. Or perhaps you simply want to set up your own repository to share a few RPM packages with the world or just your friends.

Creating your own yum repository is very simple, and very straightforward. In order to do it, you need the createrepo tool, which can be found in the createrepo package, so to install it, execute as root:

# yum install createrepo

Once the package is installed, you can begin creating your repository. You will also need some RPM packages to create the repository with. Decide where you want to store your repository; let's say, /var/ftp/repo will be the base directory.

Depending on how particular you want to get, you can dump everything to a single repository or keep things organized. I'm a big fan of organization, so let's assume you will be creating a repository for Fedora 10 and have both i386 and x86_64 packages you want to be made available with it. I would create an appropriate directory tree using the following commands:

# mkdir -p /var/ftp/repo/Fedora/10/{SRPMS,i386,x86_64}

Now copy your i386 packages to /var/ftp/repo/Fedora/10/i386, your x86_64 packages to /var/ftp/repo/Fedora/10/x86_64, and the SRPMS you have (if wanted) to /var/ftp/repo/Fedora/10/SRPMS. To easily automate the creation of the repository metadata, create a shell script called create-my-repo and place it somewhere in your PATH:

for arch in i386 x86_64
    pushd ${destdir}/${arch} >/dev/null 2>&1
        createrepo .
    popd >/dev/null 2>&1

Make the script executable and whenever you run it, it will call the createrepo tool on the two directories: /var/ftp/repo/Fedora/10/i386 and /var/ftp/repo/Fedora/10/x86_64. Once this is done, your repository is ready for use.

If /var/ftp is the available FTP root, then would be the download URL for the i386 packages. To make this available to the other client systems, create a yum repository configuration file called /etc/yum.repos.d/my.repo with the following contents:

name=My Repository

This file can be used on both i386 and x86_64 clients due to the "$basearch" specifier. It will be enabled the next time "yum update" is run.

Creating your own yum repository is very easy and very straightforward, and is a great way for administrators to distribute specialized packages within an organization.

Get the PDF version of this tip here.

Delivered each Tuesday, TechRepublic's free Linux and Open Source newsletter provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!


Vincent Danen works on the Red Hat Security Response Team and lives in Canada. He has been writing about and developing on Linux for over 10 years and is a veteran Mac user.

Editor's Picks