How to Create a Local Red Hat Repository

There are many reasons you may want a local Red Hat Enterprise Linux repository. Bandwidth is a major factor as downloading updates from the Internet can be time and bandwidth consuming. Another reason may be that your servers are not connected to the Internet and thus need to get their updates from a local source. You may have a development environment that you would prefer to not spend money on licenses for but still need to update. Whatever your reason, this tutorial will walk you through the process of getting your local repository setup.

Note: The server that serves as your repository should only serve as a repository.

Install packages needed for the repositories

yum install yum-utils createrepo httpd

Create the directories for your repositories

mkdir /var/www/html/rhel6
mkdir /var/www/html/rhel6/server
mkdir /var/www/html/rhel6/dts
mkdir /var/www/html/rhel6/dts2
mkdir /var/www/html/rhel6/rhsc

Helpful Commands

List the repos on your server both enabled and disabled.

yum repolist all

List the repos available on your subscription

subscription-manager repos --list

Enable a repo on your system

subscription-manager repos --enable=rhel-6-server-optional-rpms

Disable a repo on your system

subscription-manager repos --disble=rhel-6-server-optional-rpms

We want to have the server, dts, and rhsc (software collections) repositories enabled on the repository

Sync Repos

Once all of these repos have been enabled perform the following command for all of them changing the download_path for each to match the download_path for that repo.

reposync --gpgcheck -l --repoid=repoid --download_path=/var/www/html/rhel6/repo_name --downloadcomps --download-metadata

Note: The server repo will take the longest. Like all night long. The others should be much shorter.

Createrepo Command

Once the packages have been downloaded all that is needed is the createrepo command below for each repo

createrepo -v /var/www/html/rhel6/repo_name/ -g comps.xml

Note: The -g comps.xml is only needed for the server repo.

Setting Up Client Servers

Now you have a local repository but you need to make some changes on your Red Hat servers that will be using these repositories for updates.

First make sure that all other repos have the enabled flag set to 0 (zero) within the repo file in /etc/yum.repos.d. I wouldn't delete the repos for now because you might need them later. Simply changing the enabled flag is enough.

Now you need to create a .repo file that will be added to the /etc/yum.repos.d directory on every server using the repositories. That file should look similar to the following file.

vi /etc/yum.repos.d/name_of_repo_file.repo
name = rhel-6-server-rpms
baseurl = http://hostname_or_ip_address_of_repository/rhel6/server
gpgcheck = 0
enabled = 1

name = rhel-server-dts-6-rpms
baseurl = http://hostname_or_ip_address_of_repository/rhel6/dts
gpgcheck = 0
enabled = 1

name = rhel-server-dts2-6-rpms
baseurl = http://hostname_or_ip_address_of_repository/rhel6/dts2
gpgcheck = 0
enabled = 1

name = rhel-server-dts2-6-rpms
baseurl = http://hostname_or_ip_address_of_repository/rhel6/dts2
gpgcheck = 0
enabled = 1

Create Script and Cron Job to Update Your Repositories

Create a script named and put it in /usr/local/bin with the following contents:

vi /usr/local/bin/
echo Update script started at $(date) >> /var/log/update-repository.log
reposync --gpgcheck -l --repoid=rhel-6-server-rpms --download_path=/var/www/html/rhel6/server --downloadcomps --download-metadata
createrepo --update /var/www/html/rhel6/server/
reposync --gpgcheck -l --repoid=rhel-server-dts-6-rpms --download_path=/var/www/html/rhel6/dts --downloadcomps --download-metadata
createrepo --update /var/www/html/rhel6/dts/ \\
reposync --gpgcheck -l --repoid=rhel-server-dts2-6-rpms --download_path=/var/www/html/rhel6/dts2 --downloadcomps --download-metadata
createrepo --update /var/www/html/rhel6/dts2/
echo Update script ended at $(date) >> /var/log/update-repository.log
chmod 600 /usr/local/bin/

Note that I have it dropped into a log that I have setup to rotate monthly.

Create a file in /etc/cron.d and name it update-repository with the following content.

vi /etc/cron.d/update-repository
@weekly root /usr/local/bin/

Final Thoughts

There are many different ways to accomplish setting up a local repository and I certainly didn't invent the wheel on this one. Consult my sources below for more information and insight for your setup.


Share this page:

6 Comment(s)

Add comment

Please register in our forum first to comment.


By: Fmo

I would strongly suggest to use createrepo_c as it is much faster and consumes a lot less memory.

By: christensen143

Thanks for the suggestion. I've actually never heard of createrepo_c before you mentioned and found some speed comparisons here:

It is significantly faster. I will have to test it out and get back to you on it. Thanks for the suggestion!

By: dude

or rsync from a mirror. no need to use create repo then.

By: Jeff

To make the script executable the proper permissions are 700

chmod 700 /usr/local/bin/

By: Rahul


Is it legal to use RHEL 7 without subscription and using local repository to update the rhel patches & kernel ?

By: pvman

I hate to be specific to my circumstances, but I am trying to setup a few repositories for RHEL 6/7 and Oracle Linux 7/8.  My systems are on an isolated network.  My enterprise supplies me with a full patch set frozen sometime in the past and deltas for each month. I'd like to avoid setting up a web server on my network.  My plan is to simply add the provided patch sets to my NFS server that my Linux clients already mount.  I'm a little confused as to how to setup the directory structure to properly use the $releasever-$basearch references for all the types of patch categories (i.e., base, optional, epel, updates, etc.).

Any resources you can suggest to guide me?  Most everything I read wants to 1.) setup a web server, and, 2.) does not really address mixing all the patch categories in one repository or address how to setup several repositories that may include different distributions (CentOS, RHEL, Oracle, etc.).Maybe I'm missing the forest for all the trees in my way.