Local YUM Repository

2 Comments

Sometimes, especially when you create your own RPMs, it is extremely useful to keep them in a local YUM repository. The advantage of this is that, when you install a package, YUM automatically resolves any dependencies, not only by downloading the necessary packages from the other repositories you might have in you list, but also by using your local repo as a resource for potential dependencies.

So, when installing a package (eg my_package.rpm) with YUM, you are supposed to have already created RPM packages for all of the my_package.rpm‘s dependencies and to have updated the repository’s metadata, so that yum is able to resolve all the dependencies. If these dependencies do not exist in any of the repositories in your list, then, in short, you cannot install your package with yum.

So, in order to install an RPM package and all the other packages that it depends on, you only need to run:

# yum install my_package.rpm

How to create a local YUM repo

You will need an utility, named createrepo. Its RPM package exists in Fedora Extras. To install it, just run as root:

# yum install createrepo

Then, put all your custom RPM packages in a directory. Assuming that this directory is /mnt/fc_local_repo/, you can create all the necessary metadata for your local repository by running the following command as root or as the user that owns the directory:

# createrepo /mnt/fc_local_repo/

That’s it! Your local YUM repository is ready.

Keep in mind that every time you put any new RPMs in that directory or remove any old RPMs, you will need to run the above command again, so that the repository metadata gets updated.

Add your local repo to the list

The next thing you need to do is to add your local repository to your list of repos, so that yum knows where to find it. This info is kept in the /etc/yum.repos.d/ directory. As root, create a new text file in this directory, name it fedora-local.repo (you can use any name you like, but remember to add the extension .repo), and add the following info in it:

[localrepo]
name=Fedora Core $releasever - My Local Repo
baseurl=file:///mnt/fc_local_repo/
enabled=1
gpgcheck=0
#gpgkey=file:///path/to/you/RPM-GPG-KEY

As you can see, we used the protocol file:/// in the baseurl option. This assumes that the local repo exists in the local machine. If it exists in another machine of your internal network, feel free to use any other protocol in order to tell yum where to find your local repository, For example you can use http://, ftp://, smb:// etc.

In the above example, the GPG key check is disabled (gpgcheck=0). If you sign your packages, you can set this to "1" and uncomment the following line (gpgkey=...). This contains the path to your public key, so that YUM can verify the package signatures.

You can have as many local YUM repositories as you like.

Other uses of a local repository

Using a local repository does not only serve as a place for your custom RPMs. You can perfectly save some bandwidth by downloading all the released fedora updates in that repo and use this to update all the systems of your internal network. This will save bandwidth and time.

Further Reading

There is an excellent YUM guide at the Fedora web site. It’s well written and will help you become experts with YUM:

  1. Managing Software with YUM, by Stuart Ellis.

Local YUM Repository by George Notaras, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Copyright © 2005 - Some Rights Reserved

About George Notaras

George Notaras is the editor of G-Loaded Journal, a technical blog about Free and Open-Source Software. George is a GNU/Linux enthusiast, a self-taught programmer and system administrator. He strongly believes that "knowledge is power" and has created this web site to share the IT knowledge and experience he has gained over the years with other people. George primarily uses CentOS and Fedora and spends some of his spare time developing open-source software. Follow George on Twitter: @gnotaras

2 responses on “Local YUM Repository

  1. sanjeev Permalink →

    good article, But how to update the RPMs which are not installed in the machine and they are in the local repository?

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>