How to Create Your Own Repositories for Packages

For Linux, the most common way to distribute software is binary packages in the rpm or deb format. Most packages are included in the official distribution repositories or 3rd party software repositories. Nevertheless, there are some cases where you need to install just a few standalone packages.   You might be able to use the local package install tools, namely dpkg or rpm, however, there are cases where packages can’t be installed due to the dependencies and you need to install all dependencies manually. It might take some time and isn’t always an easy process. But there is a solution that can help – you can create your own local repository and deploy your packages to it.

Let’s discuss how to create your local repositories to make your life easier.

RPM-Based Distributions

RPM-based operating systems work with rpm packages and the most common package manager for them is yum.   While newer RPM-based operating systems use the dnf utility,  it maintains compatibility with yum repositories so these instructions also apply for dnf.

In order to create a yum repository you need to perform the following steps:

  1. Install createrepo utility
  2. Create a repository directory
  3. Put RPM files into the repository directory
  4. Create the repository metadata
  5. Create the repository configuration file

1. Install createrepo utility

To create a yum repository we need to install additional software called “createrepo” :

sudo yum install createrepo

2. Create a repository directory

You need to create a new directory that will be the location of your yum repository and will hold the desired rpm package files.

So you should decide the location of this directory and create it

mkdir <your_directory_name>

as an example let’s use /opt/rpms

3. Put RPM files into the repository directory

You should just copy or download your RPMs into the new directory

4. Create the repository metadata

The createrepo command reads through the directory with rpm packages and creates a new directory called “repodata” in it.  This directory contains the metadata information for the repository.  Every time you add additional rpm package files to your yum repository, you need to re-create the repository metadata with the “createrepo” command.

So to create the repository you need to execute:

createrepo <path_to_your_directory_with_rpms>

example:

If you already created the repository metadata and you are just adding new packages to it you need to update the repo:

5. Create the repository configuration file

A yum repository has its own configuration file and there are a few rules for it:

  • It must be located in /etc/yum.repos.d/ directory
  • It must have the .repo extension, to be recognized by yum

File options are:

  • Repository ID – One word unique repository ID (example: [myrepo])
  • Name – Human-readable name of the repository (example: name=My Repository)
  • Baseurl – URL to the repodata directory. You can use file://path if repository is located locally or ftp://link, http://link, https://link if repository is located remotely – HTTP Authentication available http://user:password@www.
  • Enabled – Enable repository when performing updates and installs (example: enabled=1)
  • Gpgcheck – Enable/disable GPG signature checking (example: gpgcheck=1)
  • Gpgkey – URL to the GPG key (example: gpgkey=http://mirror.cisp.com/)
  • Exclude – List of the packages to exclude (example: exclude=httpd,mod_ssl)
  • Includepkgs – List of the packages to include (example: include=kernel)

Required yum repository configuration file options are:

  •  Repository ID
  •  Name
  •  Baseurl
  •  Enabled

For example:

Debian-Based Systems

A Debian repository is a set of Debian binary or source packages organized in a special directory tree with various infrastructure files.

In most cases on Debian-based systems all repositories are managed by the “apt” utilities (apt, apt-get, apt-cache, etc…)

To create an apt repository you need to perform the following steps:

  1. Install dpkg-dev utility
  2. Create a repository directory
  3. Put deb files into the repository directory
  4. Create a file that apt-get update can read
  5. Add info to your sources.list pointing at your repository

1. Install dpkg-dev utility

This package provides the development tools required to unpack, build and upload Debian source packages.

You can install it using apt-get:

2. Create a repository directory

You need to create a new directory that will be the location of your deb repository and will hold the desired deb package files.

You should decide the location of this directory and create it

mkdir <your_directory_name>

as an example let’s use /opt/debs

3. Put deb files into the repository directory

You should just copy or download your rpm files into the new directory

4. Create a file that “apt-get update” can read

For this, you should run dpkg-scanpackages command.

dpkg-scanpackages  sorts through a tree of Debian binary packages and creates a Packages file, used by apt, dselect, etc, to tell the user what packages are available for installation.

5. Add info to your sources.list pointing at your repository

You need to add a line into Sources.list in the following way:

deb file:///<path_to_your_repo_dir> ./

For example:

If you built packages and didn’t sign them with gpg or you haven’t imported the gpg key which was used for signing packages in your repo and you trust them, you can use the following definition to skip the signing check.

[trusted=yes]

For example:

There are various reasons for building a repository yourself.  You might just have a few packages with local modifications that you want to make available, you may want to run a local mirror with packages used by several machines to save bandwidth, or you have built packages yourself and want to test them before publication.  These steps can provide a solution for you.

Share this post

Leave a Reply