Create yum repository

In this tutorial we’ll explain how to set up a yum rpm repository for your Red Hat/CentOS Server.

At first you need to set up a web directory for the repository using your preferred web server. In this example
we’ll be using the Apache2 server.

Install apache2 by running following command. While at it, also install ‘createrepo’, a package needed to create the needed xml files for your repo.

sudo yum install httpd createrepo

The httpd config for the repository is pretty straight forward. A simple config would look like this:

    Listen IP:80

    <VirtualHost IP:80>
    ServerName repo.example.com //Insert your address here
    DocumentRoot /var/repo

    <Directory /var/repo>
        Options Indexes
    </Directory>

    ErrorLog /var/log/httpd/repo_error.log
    LogLevel debug

    CustomLog /var/log/httpd/repo_access.log combined

    </VirtualHost>

Save the config at /etc/httpd/conf.d/repo.conf, create following directory,

mkdir -p /var/repo/main/RPMS

then restart the httpd server, using

sudo service httpd restart

Make sure that the config is correct by checking if the server is accessible. Use a browser and go to
repo.example.com and see if it comes up without a problem.

Once it’s running, create a config file for the repository, in

/etc/yum.repos.d/repo.conf

and insert following

[myrepo-main]
name=My Main RPM Repository
baseurl=http://repo.example.com/main
gpgcheck=1
enabled=1

You can add more repositories to the config, e.g.

[myrepo-alt]
name=My alternative RPM Repository
baseurl=http://repo.example.com/alt
gpgcheck=1
enabled=1

and so forth.

Once done, save the file.

Now, move your RPMs into /var/repo/main/RPMS and run

createrepo /var/repo/main

If you have set up another repo in the config file, run the command for each sub directory, e.g.

createrepo /var/repo/alt

This will create a directory called ‘repodata’ containing all necessary info on the yum repo in xml format.
Run this command every time you add new rpm files to your reposotitory.

Now, run

sudo yum clean all

followed by another yum command, such as

sudo yum info httpd

to see if yum picks up on your repo.

If your repo appears in the list and no problems are found, your repository is up and running.

This way, your repo is open to the public.
If you don’t want your repo accessible to the public, you can set up an http auth for your directory, and edit your repo.conf in the following way:

baseurl=http://username:password@repo.example.com

Equally if you want to run your repo through https, just adjust your config as well, and it works.

In another post we’ll go through creating rpm files.