Centos/RHEL/Fedora Create Your Own YUM Repository

Published on Author gryzliLeave a comment

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.

Prerequisites

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:

/var/www/html/

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:

/repos/CentOS/6/all_packages/

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:

 

/repos/CentOS/6/5/RPMS/some_package.rpm

/repos/CentOS/6/5/SRPMS/some_package.rpm

…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 :

[[email protected]_srv ~]# cd /repos/CentOS/6/all_packages/                               [[email protected]_srv all_packages]# createrepo .  

 

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: 

[[email protected]_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”

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Captcha * Time limit is exhausted. Please reload CAPTCHA.