Centos/RHEL/Fedora Create Your Own YUM Repository

Published on Author gryzli

If you have learned how to build your own rpm packages (or want to use custom already built ones) , you maybe want to use your own yum repository for installing these packages.

In the following how-to I will show you how to easily setup a yum repository.


1| Install createrepo

First you need to install the createrepo package.

yum install -y createrepo

This package will give you the ability to generate repository meta data, which will later be needed by the client.


2| Install some web server (Apache, Nginx, Lighttpd …etc…)

Next you must assure you have some running Web Server. In the current example I assume your web server is running and serves the directory:


Also I assume you have sub-domain pointed to your web server, named for example:

repo.example.com   –> YOUR_IP:/var/www/html

Installing Web server is a straight forward porcess, which I won’t explain in detail here.


Configuring the Yum Repository

Now it’s time to configure your yum repository, which is very easy process.

1| Prepare repository directory

Let say you will use the following directory for your repository:


Here are the steps you need to do

  1. Create Repo directory

    mkdir -p /repos/CentOS/6/all_packages/

  2. Link the repo directory to your web server

    cd /var/www/html
    ln -s /repos .

  3. Copy all your custom RPM packages to the repos directory

    cp /path/to/custom_rhel6_package.rpm /repos/CentOS/6/all_packages

In my example I will put all packages for a given distro major version (Centos 6 in this case) in the same directory. Of course you could configure your repository more granulary, for example:




…and so on. In this case you must make sure, to configure your client’s repo file appropriately .



2| Generate repository meta files

Meta file generation is easy and is made with the “createrepo” command :

[root@repo_srv ~]# cd /repos/CentOS/6/all_packages/                               [root@repo_srv all_packages]# createrepo .  

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


If you are creating repository for Centos 5.x servers, keep in mind, that Centos 5 doesn’t support sha256 checksums (which is default for newer createrepo versions). So you must explicitly change the checksum algorithm to sha1: 

[root@repo_srv all_packages]# createrepo --verbose -s sha1  /repos/CentOS/5/all_packages/  



The following command will create meta-directory named “repodata”, where repository data is generated for use by  the client.


Configuring the client (add the yum repository)

In order to use your repository by your clients, you will need to add some additional repository configuration file to the yum directory “/etc/yum.repos.d”

root@srv [~]#cd /etc/yum.repos.d

root@client_srv [/etc/yum.repos.d]#vim custom_repo.repo

name=Extra packages from Custom Repo