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 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:
createrepo utility
To create a yum repository we need to install additional software called “createrepo” :
sudo yum install createrepo
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
1 mkdir /opt/rpms
You should just copy or download your RPMs into the new directory
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:
1 createrepo /opt/rpms
If you already created the repository metadata and you are just adding new packages to it you need to update the repo:
1 createrepo --update /opt/rpms
A yum repository has its own configuration file and there are a few rules for it:
File options are:
Required yum repository configuration file options are:
For example:
1 [customrepo]<br>name=CustomRepository<br>baseurl=file:///opt/rpms<br>enabled=1<br>gpgcheck=0
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:
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:
1 sudo apt-get install dpkg-dev
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
1 mkdir /opt/debs
You should just copy or download your rpm files into the new directory
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.
1 cd /opt/debs<br>dpkg-scanpackages . /dev/null > Release
You need to add a line into Sources.list in the following way:
deb file:///<path_to_your_repo_dir> ./
For example:
1 deb file:///opt/debs ./
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:
1 deb [trusted=yes] file:///opt/debs ./
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.