Skip to main content

Create a Basic Local DEB Package Repository

·578 words·3 mins
System-Administration Linux Packaging Deb Debian Ubuntu
Table of Contents

Requirements
#

The first thing is that the dpkg-dev package needs to be locally installed:

# Ensure package cache is up-to-date
$ apt update
# Install the required toolset
$ apt install dpkg-dev

Next, is the directory that the repository will reside in, such as:

$ mkdir -p /opt/test-repo/

And finally, is a package or set of packages that the repository that will be made available from it, as an example a newer version of a package than is available from your base distro:

$ cd /opt/test-repo/
$ wget http://us.archive.ubuntu.com/ubuntu/pool/universe/m/meson/meson_0.61.2-1_all.deb

Generate Repository Metadata
#

Details can be found on the Debian Repository/Format page.

Packages File
#

Next, create the Packages compressed file(s), which for now will effectively have the same content as the Release file, but can be compressed via different compatible formats:

$ cd /opt/test-repo/
# Not compressed
$ dpkg-scanpackages . /dev/null > Packages
# Compressed via XZ
$ dpkg-scanpackages . /dev/null | xz -c > Packages.xz
# Compressed via Gzip
$ dpkg-scanpackages . /dev/null | gzip -c > Packages.gz

This will give some output indicating which files/packages were found and recorded, such as:

dpkg-scanpackages: warning: Packages in archive but missing from override file:
dpkg-scanpackages: warning:   meson
dpkg-scanpackages: info: Wrote 1 entries to output Packages file.

With the subsequent Package file’s contents looking something like the contents one would normally see when running apt info <package>, like so:

Package: meson
Version: 0.61.2-1
Architecture: all
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Installed-Size: 3255
Depends: python3:any (>= 3.7~), ninja-build (>= 1.6), python3-pkg-resources, python3-distutils
Recommends: dpkg-dev
Filename: ./meson_0.61.2-1_all.deb
Size: 518618
MD5sum: ca899f3b1ac841d7be10263a7bac8268
SHA1: fafa35ab83906b7b75d805cbe14bbc6ed5d21023
SHA256: 54d4a5b9f2c82c37a5ce0bce9027c623aab5505437d87f12fa858ecf32d0b506
Section: devel
Priority: optional
Multi-Arch: foreign
Homepage: https://mesonbuild.com
Description: high-productivity build system
 Meson is a build system designed to increase programmer
 productivity. It does this by providing a fast, simple and easy to
 use interface for modern software development tools and practices.

Release File
#

NOTE: Normally, Release files in ‘proper’ repositories contain metadata about the distribution and cecksums for indices, however for a local repository these are skipped and it effectively becomes a plaintext Packages file.

Next, create the Release file, which lists package info:

$ cd /opt/test-repo/
$ dpkg-scanpackages . /dev/null > Release

Add local repository to APT
#

With the local repository now having the packages and metadata, it is time to let APT know to look at it for packages. To do so, either update the /etc/apt/sources.list file, or create a new one in the /etc/apt/sources.list.d/ directory, such as /etc/apt/sources.list.d/test.repo and add the following line:

deb [trusted=yes] file:/opt/test-repo/ .

Since the content of our local repository doesn’t have any signing going on, add the [trusted=yes] to tell APT that to trust the content and not require the usual security/verification checks.

Check APT can use the repository
#

Tell apt to update the repository cache, then query for and/or install the new package as usual, for example:

$ apt update
$ apt info meson

From this example would yield:

Package: meson
Version: 0.61.2-1
Priority: optional
Section: devel
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Jussi Pakkanen <jpakkane@gmail.com>
Installed-Size: 3333 kB
Depends: python3:any (>= 3.7~), ninja-build (>= 1.6), python3-pkg-resources, python3-distutils
Recommends: dpkg-dev
Homepage: https://mesonbuild.com
Download-Size: 519 kB
APT-Sources: file:/opt/test-repo ./ Packages
Description: high-productivity build system
 Meson is a build system designed to increase programmer
 productivity. It does this by providing a fast, simple and easy to
 use interface for modern software development tools and practices.

Noting the APT-Sources: file:/opt/test-repo ./ Packages line, indicating that APT found this package from the local repository that was just added.