Creating Your Own YUM Repo

Intro

The need often arises for a dedicated, local repository of software packages from which to install, update, and otherwise manage your software. The idea is that you are not pulling form a repository online, but you have created one locally and filled it with the software packages you need (and maybe purposely left out what you don't need). The use cases for this are myriad, but here are two common ones:

  • A machine has no internet connection and therefore cannot reach common software repos.
  • You have many unique packages and dependencies that are hard to find in common repos.

If you have experienced these problems and can type a few Linux commands, look no further for your solution; its name is createrepo!

Note: This blog pairs well with another one I wrote that gives more detail about hosting a web server and making your yum repo available there. That blog can be found here

About YUM, .rpm Files, and Createrepo

On Red Hat/CentOS machines, it is common to manage your software with YUM (Yellowdog Updater, Modified)1, which is essentially a way to organize, install, and manage software via .rpm (Red Hat Package Manager) files.2 YUM will pull .rpm's from a repository, remote or local, and install them on your machine as well as update, manage, and uninstall them.

Createrepo is essentially a Python program that allows you to take a directory of .rpm's and use it to create a local repository to manage with YUM.3 It works by maintaining the metadata of the .rpms's and exposing that metadata to YUM so it can be searched and used to manage your software.

The .rpm metadata is "an XML format for describing the critical metadata from an rpm package for dependency resolving and installation."3 The core service that createrepo provides is to generate this .rpm metadata so it can be managed locally.

That is it. It's that simple.

Now that you have a grasp on the purpose of createrepo, let's get into the nuts and bolts of how to install it and use it.

Installing and Using Createrepo

The first thing you will want to do is to download all of the .rpm's you want in your repo and copy them to a directory that makes sense for your system. For this example, we will use /srv/local/repo. The remainder of this section will reference the createrepo documentation.4

To install create repo, you can use yum:

yum install createrepo  

or just download it from the website:

http://createrepo.baseurl.org/  

The best part about createrepo is how simple it is to use. Once it is installed, you just need to run one command to make your directory of .rpm's into a working yum repo. The command is:

createrepo /srv/local/repo  

If everything worked correctly and you did not see any errors, your directory should now have another directory called repodata inside of it. This is where the metadata we talked about earlier will live.

Now that you have your repo, all you need to do is point to it in your yum config files and then you can begin to use it to manage your software! To do that, follow these commands:

cd /etc/yum.repos.d/  
vim custom.repo  

And add the following:

[local-repo]
name = Local Repo  
baseurl = file:///srv/local/repo/  

*Note: If you want this machine to act as a web server that other machines can pull from, you just need to change the baseurl to be something like: baseurl = https://servernameORip/local-repo/, host the repo under /var/www/html, and make sure your web server is properly configured. More info on configuring a web server for this purpose can be found here

There are a few more configs you can add into your .repo file, but this is all you need to get started!

Now you can test it out by running the following commands:

yum clean all  
yum repolist (here, you should see your 'Local Repo')  
yum install {software name}  

And that is all there is to it! Now anytime you add a software package to your repo, you will have to rerun the createrepo /srv/local/repo command to regenerate the metadata.

If you are new to yum, here is a handy cheatsheet.

Have fun finding packages to put in your repo and let me know if you have any questions!
[email protected]

Sources

  1. YUM
  2. Digital Ocean
  3. Createrepo
  4. Createrepo Docs