How to Create Your Own Repositories for Packages (2024)

How to Create Your Own Repositories for Packages (1)

How to Create Your Own Repositories for Packages (2)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

Shell

1

mkdir /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:

Shell

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:

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:

INI

1

2

3

4

5

[customrepo]

name=CustomRepository

baseurl=file:///opt/rpms

enabled=1

gpgcheck=0

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 thedevelopment tools required to unpack, build and upload Debian source packages.

You can install it using apt-get:

Shell

1

sudo apt-get install dpkg-dev

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.

Shell

1

2

cd /opt/debs

dpkg-scanpackages . /dev/null > Release

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:

Shell

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:

Shell

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.

Try Now: Free your applications with Percona Distribution for MySQL

Related

2 Comments

Oldest

Newest Most Voted

Inline Feedbacks

View all comments

How to Create Your Own Repositories for Packages (3)

Niels Kristian Jensen

2 years ago

This fails with Ubuntu 20.04 LTS. Tried the above, and “apt update” fails :

Err:4 file:/home/oem/packages ./ Packages
File not found – /home/oem/packages/./Packages (2: No such file or directory)

The file does exist (created by dpkg-scanpackages)

/home/oem/packages/Release
ubuntu@udg:~$ ls -al /home/oem/packages/Release
-r-xr-xr-x 1 root root 6771 Aug 23 11:19 /home/oem/packages/Release

How to Create Your Own Repositories for Packages (4)

Niels Kristian Jensen

2 years ago

dpkg-scanpackages . /dev/null > Release should be changed to:

dpkg-scanpackages . /dev/null > Packages

At least, that works for me on Ubuntu 20.04 LTS

7

How to Create Your Own Repositories for Packages (2024)

FAQs

How to Create Your Own Repositories for Packages? ›

To create a new repo, you'll use the git init command. git init is a one-time command you use during the initial setup of a new repo. Executing this command will create a new .git subdirectory in your current working directory. This will also create a new main branch.

What is the command to create a repo in Linux? ›

To create a new repo, you'll use the git init command. git init is a one-time command you use during the initial setup of a new repo. Executing this command will create a new .git subdirectory in your current working directory. This will also create a new main branch.

What are packages and repositories? ›

Packages get to libraries from repositories by installation. Think of your data science workbench as a kitchen: The repository is the grocery store, a central place to get packages. The library is the pantry, where you keep your own private set of packages.

What is APT package repository? ›

For APT, a repository is a directory containing packages along with an index file. This can be specified as a networked or CD-ROM location. As of 14 August 2021, the Debian project keeps a central repository of over 50,000 software packages ready for download and installation.

How do APT repositories work? ›

It simplifies the process of installing, updating, and removing software. APT works with repositories — designated locations that host packages and update information. Mastering APT repository management ensures you have access to the software you need and that your system remains secure and up to date.

How to setup a local repository in Ubuntu? ›

Step 1) Create a local Apache Web Server

First off, log in to your Ubuntu 20.04 and set up the Apache web server as shown. Apache's default document root directory is located in the /var/www/html path. We are later going to create a repository directory in this path that will contain the required packages needed.

What is a Linux package repository? ›

Linux Package Repositories are software repositories that contain binary packages, metadata, and dependency information for installing and managing programs on Linux.

What is a repository example? ›

The repository example consists of a client application that sets up three DNA repositories (named "Cars", "Airplanes", and "UFOs") and a federated repository ("Vehicles") that dynamically federates the information from the other three repositories.

What is the difference between repository and package? ›

A package repository, registry, or feed is a place to store all of your packages. Package repositories work closely with package managers, and the terms can get mangled when talking about software tools, like Cloudsmith or JFrog's Artifactory, that support most software packages.

Which command creates a local git repository? ›

The git init command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new, empty repository. Most other Git commands are not available outside of an initialized repository, so this is usually the first command you'll run in a new project.

Top Articles
Latest Posts
Article information

Author: Chrissy Homenick

Last Updated:

Views: 6044

Rating: 4.3 / 5 (54 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Chrissy Homenick

Birthday: 2001-10-22

Address: 611 Kuhn Oval, Feltonbury, NY 02783-3818

Phone: +96619177651654

Job: Mining Representative

Hobby: amateur radio, Sculling, Knife making, Gardening, Watching movies, Gunsmithing, Video gaming

Introduction: My name is Chrissy Homenick, I am a tender, funny, determined, tender, glorious, fancy, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.