Tuesday, 28 May 2013

Create a local yum repository using ISO

Create a Local Yum Repository using ISO file

This tutorial is going to show you how to create a local Yum Repository on your CentOS/ Red hat/ Fedora machine using their respective ISO DVDs...

There are a few things to note in this tutorial however:

This tutorial will help you set up a local Repo successfully, however the availability of RPMs strictly depends on the version of the DVD release you are using. Since this Repo is created using the DVD as a RPM source, you wont get all the RPMs the you may want.. but definitely, the necessary ones are always covered in the DVD.

This tutorial can be followed to create a local Repo where there is no internet connectivity present (Hence, I call it as an Offline Repo !!)
There are other ways of setting this up as well, but I have documented it using standard steps that are generally very easy to manipulate on any CentOS machine irrespective of version.

NOTE: The following tutorial uses RHEL 6.2 64 Bit ISO DVD. You can however use the same steps for either the latest release of CentOS or Fedora as well.
Make sure you have enough of disk space available for the following tutorial. We will need approx 5 GB of it.

There are two ways to go about creating an offline/ local repo on your system:

  1. Using createrepo command
  2. Using localmedia.repo file

Using createrepo command:

Mount the ISO file (DVD) on your machine. To check whether it has been successfully mounted, run the mount command as shown. You should see the output as shown below:

# mount

Once mounted, we now need to create a new directory in /var/www/html folder. You can name this directory in accordance with the flavor of ISO you are using. In my case, I am using a RHEL 6.2 ISO.

# mkdir -p /var/www/html/rhel62

Next, we now need to copy all the RPMs from the mounted ISO File (DVD) to this new folder (rhel62). The RPMs in the ISO will generally reside in a folder typically named "Packages".

# cp -R /media/RHEL_6.2/Packages* /var/www/html/rhel62/ 

Once the copying is done, if you do a word count (wc -l) in the rhel62 folder, you should see a large number of RPMs listed here.

Now once all the RPMs have been successfully copied, we need to install few necessary packages in order to set up our local repo using "createrepo".

createrepo is a program that creates a repomd (xml-based rpm metadata) repository from a set of RPMs. To know more about createrepo, click HERE.

First, we need to install a couple of dependent packages for our createrepo command. Install the following two RPMs:
  • deltarpm
  • python-deltarpm 
NOTE: These two RPMs will be present within the ISO itself.

Once these dependencies are done, we can now install the createrepo RPM as shown.

With the RPM now installed, in your rhel62 folder, run the following command to create your local repo.

# createrepo .

You can run this command from withing that directory or even one level up as createrepo will descend down to all LOWER directories too. We ran this command at /var/www/html/rhel62 
directory level. When you run createrepo, it will generate a directory called repodata in the directory where it is run.

NOTE: This step also takes little time (approx 3-4 mins) depending on the number of RPMs present.
With this step, our Repo is almost complete. We will now setup apache server (provided with the ISO installation) 

# vi /etc/httpd/conf/httpd.conf

In this file, you only have to make changes in two places. 



Once the changes are done, save and close the file.

Next, enable the httpd service to be switched on even after boot using chkconfig command

Start the httpd service if its stopped.

# service httpd status
# service httpd start
# chkconfig httpd on

NOTE: If there is some error message while starting the httpd service, suggest you check out the httpd.conf file that we earlier edited for any errors. 

Next, we now need to create our own repo file. For that, go to /etc/yum.repo.d folder and rename all the existing repo files (*.repo) to .repo.old (OR) you can just create a new folder there and move all these repo files in it (as down below)

# cd /etc/yum.repo.d
# mkdir old 
# mv *.repo old/

With this done, create a new .repo file as shown below:

# vi localrepo.repo 

In this new file, type in the following info:



Once entered, save and close the file.

Clean the Repository

# yum clean all

List the Repository

# yum repolist

If you get an output similar to the one below, then you have successfully configured a local RHEL yum repository on this machine :-) 

Using localmedia.repo File

This is a much easier and simpler way to set up a local repo. All you need to do is mount the ISO file as done in our previous steps

Create a new repo file at /etc/yum.repo.d location with the following information:


Once entered, save and close the file.

Run the clean up and repolist commands for the newly created repo

# yum clean all
# yum repolist

You should see the newly added Repo as shown below

So what's the difference between using the createrepo command and simply using the file:/// path?

Its simple. If you add or remove more RPMs to your repo, you will need to run the createrepo command to build the repodata.xml file. This you cant do when using the localmedia.repo file. In short, if you plan to add external RPMs to your repository, then better to work with the createrepo way. Else, the easier localmedia file way.

That's it for now. Feel free to drop your comments/ suggestions by.

Stay tuned for more.. coming your way soon..


1 comment :

Baju Muslim Anak said...


I've recently used one of your templates and it's been awesome!

However, just today, I wanted to re-shuffle my layout, but, it isn't an exact layout as my blog. *sigh*..I don't know if I make any sense, but, how am I suppose to reshuffle my layout if it doesn't look like the intended layout for the blog? Is it a html malfunction?

i don't know where else to post this up but, I really hope someone replies. thanx!

- Cara Mengatasi Anak Susah Makan dengan Laperma Platinum
- Toko Olahraga Online Murah, Lengkap, Aman dan Terpercaya
- Franchise Minuman Coklat, Waralaba Minuman, Nyoklat, Nyoklat Super

Post a Comment