Loading...

Lab 72: Creating a Local Package Repository

Build local repositories for RPM, APT, and pacman so you can distribute internal packages without relying on external mirrors. Generate the correct metadata artifacts so clients can query and install packages the same way they do from public repos.

packages repos operations

Scenario

You need to host and maintain local package repositories for custom software. Your task is to stage packages into the correct repo locations and generate the metadata that RPM-based, Debian-based, and Arch-based clients expect.

Operator context

Local repositories are common in locked-down environments, air-gapped networks, and internal release pipelines. The work is mostly “put packages in the right place” plus “generate the index files correctly,” then validate client behavior.

Objective

  • Create a local RPM repo directory and populate it with .rpm packages.
  • Generate RPM repository metadata using createrepo.
  • Create a local APT repo directory and populate it with .deb packages.
  • Build an APT package index using dpkg-scanpackages and compress it to Packages.gz.
  • Create or update a pacman repository database using repo-add.

What You’ll Practice

  • Staging RPMs under a web-served path (/var/www/html/repo) for repo access.
  • Generating RPM metadata with createrepo.
  • Building a minimal APT repository index with dpkg-scanpackages and gzip compression.
  • Maintaining a pacman repo database with repo-add for *.pkg.tar.zst packages.

Walkthrough

Step 1 : Prepare the local RPM repository directory and copy packages.
Command
mkdir -p /var/www/html/repo && cp *.rpm /var/www/html/repo

This stages all RPMs into a single directory that can be served via HTTP. The repo tooling expects package files to be present before metadata is generated.

Repository directory created and RPM files copied.
Step 2 : Generate RPM repository metadata.
Command
createrepo /var/www/html/repo

This creates the repodata/ directory and the metadata files that yum/dnf clients read when they query the repository.

Spawning worker 0 with 1 pkgs
Workers finished
Saving Primary metadata
Repo created successfully.
Step 3 : Prepare a local APT repository directory and copy packages.
Command
mkdir -p /srv/aptrepo && cp *.deb /srv/aptrepo

This stages Debian packages into a directory you can serve locally (HTTP/file share). The next step generates the package index clients use.

APT repository folder populated.
Step 4 : Generate the APT package index and compress it.
Command
dpkg-scanpackages /srv/aptrepo /dev/null | gzip -9 > /srv/aptrepo/Packages.gz

This builds a minimal Packages index and writes a compressed Packages.gz, which is a common format for small local repos.

Package list generated and compressed for apt indexing.
Step 5 : Create or update a pacman repository database.
Command
repo-add myrepo.db.tar.gz *.pkg.tar.zst

This creates or updates the pacman repository database and indexes all packages in the current directory, enabling clients to install them as a standard repo.

:: Creating 'myrepo.db.tar.gz' database...
:: Adding package 'custompkg-1.0-1-x86_64.pkg.tar.zst'
Repo index updated.

Reference

  • mkdir -p <dir> && cp *.rpm <dir> : Stage RPMs into a repository directory.
  • createrepo <repo_dir> : Generate RPM repository metadata under <repo_dir>/repodata/.
  • mkdir -p /srv/aptrepo && cp *.deb /srv/aptrepo : Stage Debian packages into a repo directory.
  • dpkg-scanpackages <dir> /dev/null : Scan a directory of .deb files and produce a Packages index.
  • gzip -9 > Packages.gz : Compress the Packages index for distribution.
  • repo-add <repo.db.tar.gz> *.pkg.tar.zst : Create/update a pacman repository database with packages.