RepoFlow Team · June 1, 2025

Mirror Debian and Ubuntu Repositories

Learn how to mirror the official Debian or Ubuntu repositories for offline or secure setups using apt-mirror or rsync.

If you're managing systems in isolated or secure environments, such as air-gapped networks or internal infrastructure, you may need full local access to Debian or Ubuntu packages without relying on the public internet. This guide explains how to mirror the repository safely and efficiently using tools that are easy to set up and maintain.

This is ideal for organizations that want full control over package availability, improve install speeds, or ensure resilience in restricted environments.

Prerequisites

You will need:

  1. A Linux machine with enough storage space (Debian mirrors can be large)
  2. Internet connection for the initial sync
  3. apt-mirror rsync installed
  4. One of these installed: apt-mirror rsync debmirror

Option 1: Using debmirror

debmirror is a powerful and flexible tool to mirror both Debian and Ubuntu repositories.

Install debmirror:

sudo apt update
sudo apt install debmirror gnupg

Example: Mirror Debian (Bookworm)

debmirror --arch=amd64 \
 --method=http \ --host=deb.debian.org \ --root=debian \ --dist=bookworm,bookworm-updates \ --section=main,contrib,non-free \ --nosource \
 /your/local/mirror/debian

Example: Mirror Ubuntu (Focal)

debmirror --arch=amd64 \
 --method=http \ --host=archive.ubuntu.com \ --root=ubuntu \ --dist=focal,focal-updates,focal-security \ --section=main,universe \ --nosource \
 /your/local/mirror/ubuntu

Option 2: Using apt-mirror

apt-mirror is a tool built specifically for mirroring APT repositories like Debian and Ubuntu.

Install apt-mirror:

sudo apt install apt-mirror

Install the dependencies:

sudo nano /etc/apt/mirror.list

Add the repositories you want to mirror:

deb http://archive.ubuntu.com/ubuntu focal main restricted universe multiverse

Then run the mirror:

sudo apt-mirror

The downloaded .deb files will be saved in /var/spool/apt-mirror.

Option 3: Using rsync

To mirror a full Debian or Ubuntu repository using rsync, use one of the following commands depending on the distribution:

For Debian

rsync -aH --progress \
rsync://mirror.cogentco.com/debian-cd/ \
./debian-cd/

If you encounter an “unauthorized” error when using this mirror URL, you can try other available options listed at https://www.debian.org/mirror/list

For Ubuntu

rsync -aH --delete --progress \
 rsync://archive.ubuntu.com/ubuntu/ \
 /your/local/mirror

If you only need .deb files for specific architectures (like amd64), you can filter with:

rsync -aH --delete --progress \
 --include='*/' \
 --include='*amd64.deb' --include='*all.deb' \
 --exclude='*' \
 rsync://archive.ubuntu.com/ubuntu/ \
 /your/local/mirror

This reduces storage and speeds up the sync process by skipping unnecessary files.

Optional: ftpsync (Debian-only, advanced use)

ftpsync is an advanced tool officially maintained by the Debian mirror team. It is used to synchronize Debian repositories in a reliable and automated way, with built-in support for locking, logging, timestamp validation, and efficient rsync-based mirroring.

More details and setup instructions: https://www.debian.org/mirror/ftpmirror

Notes on .deb File Structure

After syncing, all .deb packages will be located under the pool/ directory. Example:

/your-local-mirror/pool/main/libb/libbabeltrace/
libbabeltrace-dev_1.3.2-1_amd64.deb

You can then serve your mirror using a static HTTP server or expose it via file:// or http:// for internal APT clients.

Mirroring the Debian repository ensures long-term availability, faster installs, and zero reliance on external mirrors. Whether you're setting up a secure environment or optimizing your CI/CD infrastructure, this method provides full package control.

Join our mailing list