Linux Package Mirror: What It Is and How to Choose One

What is a Linux package mirror and what does it do?
A Linux package mirror is a server that publishes an exact copy of a distribution's software repository. Package managers such as apt and dnf download updates from these mirrors instead of one central server. The load spreads out, downloads come from a nearby machine, and updates keep flowing even when the main archive slows down.
This guide looks at the Linux package mirror from the view of a website owner, store manager or developer. We are a digital marketing and web team, not a hosting company. Because of that, everything here rests on official distribution documentation. Check your own distribution's manual before you run any command on a live system.
First you will see how apt and dnf find their mirror. Then we cover how a nearby mirror changes speed, how GPG signatures protect you, and when running your own mirror makes sense.
How is a Linux package mirror different from a repository or a cache?
Three terms get mixed up, so it helps to separate them. A repository holds packages and the index files that describe them. A mirror is a copy of that repository. However, a caching proxy does not keep a full copy; it only remembers the packages someone asked for.
| Term | What it holds | Best used for |
|---|---|---|
| Official repository | The distribution's primary package archive | The single source everything starts from |
| Public mirror | A regularly synchronised copy of the archive | Geographic proximity and load sharing |
| Internal (private) mirror | A copy of the packages your organisation selects | Large fleets and closed networks |
| Caching proxy | Only packages that were requested before | Cutting repeat downloads without much disk |
In short, every mirror is a repository, but not every repository is a mirror. Debian's documentation also lists caching proxies such as apt-cacher-ng, squid and varnish as a separate option next to full mirroring.
Where do apt and dnf read the mirror address?
Both package managers read the address from small text files. Therefore, changing those files changes which mirror your server updates from. That is why the location and format of each file matter.
- apt reads /etc/apt/sources.list and the /etc/apt/sources.list.d/ directory.
- Debian and recent Ubuntu releases use a line-based format called deb822, and those files end in .sources.
- dnf reads repository definitions from .repo files, which usually live in /etc/yum.repos.d/.
- Inside a .repo file, the address comes from a baseurl, mirrorlist or metalink line.
Look inside the directory first to see which format your system uses. File names and defaults differ between distributions, so compare against the manual for your release.
How do you read the sources file on Debian and Ubuntu?
According to the Debian wiki, the main configuration lives in /etc/apt/sources.list.d/debian.sources. Ubuntu 24.04 LTS and later define their repositories in /etc/apt/sources.list.d/ubuntu.sources. Older Ubuntu releases still use /etc/apt/sources.list.
The example below follows the deb822 layout from the Ubuntu documentation, pointed at an internal mirror. The domain is a placeholder, and you replace CODENAME with the short codename of your release.
Types: deb
URIs: https://mirror.example.com/ubuntu
Suites: CODENAME CODENAME-updates CODENAME-backports
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
The concrete answer to what a Linux package mirror is on your server is a single URIs line in this file. You only need four fields. URIs is the mirror address, Suites names the release and update channels, and Components lists the package groups. Signed-By points to the key that apt trusts for this repository.
To convert an older file, the Debian wiki suggests the apt modernize-sources command. Still, copy the file somewhere safe first.
How do mirrorlist and metalink work in dnf?
The dnf configuration reference describes baseurl as a list of repository URLs that dnf tries in the order you give them. A mirrorlist or metalink works differently, because it is a single URL that returns a list of suitable mirrors, so each client can land on one close to it.
For a public mirror, you will often see mirrorlist or metalink. When you run an internal mirror, you write your own address in baseurl instead. The difference is simple: the distribution manages the list in the first case, and you make the choice in the second.
However, if a repository cannot be reached, dnf fails by default. The reference describes skip_if_unavailable, which lets dnf carry on and disable a repository it could not sync. On a production server, enable that behaviour on purpose, because a missing security repository could be skipped without anyone noticing.
The fastestmirror option in the main configuration uses TCP socket latency to find the closest mirror, as the reference puts it. max_parallel_downloads sets how many packages download at once. Read your distribution's defaults before you change either one.
How does a nearby mirror affect speed and availability?
Download time depends on two things: the network path between your server and the mirror, and the load on the mirror at that moment. A close mirror usually gives lower latency and steadier throughput. For the network side, see our guides on ping, latency and RTT and hosting bandwidth.
Speed is not the only reason, because availability matters just as much. For example, if a mirror goes down for maintenance or its link saturates, your updates stall. A mirrorlist or metalink lowers that risk because the list contains several mirrors.
For example, if your deployment pipeline downloads packages on every run, a slow mirror delays every release. Even the time it takes to ship a site update can depend on your mirror choice. We do not quote numbers, because the effect depends on your network. To measure it, then, run the same update against two mirrors and compare the times.
Why does the Linux package mirror matter to a website owner?
If you run your site on a VPS, a package mirror works for you every day without being noticed. The first apt update on a fresh server talks to one. So does the security patch you pull, the Docker image you build and the deployment job you trigger.
So the mirror becomes part of your security and release process. When a security update arrives late, the weakness stays open longer. When the mirror slows down, builds take longer, and an urgent fix on a campaign day ships late.
Still, not every site owner needs to touch the mirror setting. On shared hosting, however, this layer already belongs to your provider. If you manage your own VPS, knowing what the default is and keeping it on purpose is often enough.
How do you choose the best mirror for your servers?
Do not rely on one criterion. The distribution's own mirror list is the safest starting point, because the mirrors on it follow synchronisation rules. After that, weigh these points against your network:
- Geographic proximity: a mirror in your server's country or city usually has lower latency.
- Protocol: choose a mirror that supports HTTPS whenever you can.
- Freshness: the mirror should sync with the main archive without falling behind.
- Bandwidth and capacity: it should not crawl at busy hours.
- Continuity: it should have a known operator, such as a university or an organisation.
We do not promote any operator, because the choice depends on your network. The healthiest approach is to pick a few candidates from the official list near you and measure them. You can also inspect the network behind a mirror with our IP lookup tool.
Which errors show up when a mirror is out of date?
If a client pulls updates before the mirror finishes syncing, index files and packages may not match. In that case apt most often reports a Hash Sum mismatch. Meanwhile, a 404 Not Found error means the package left the mirror or has not arrived yet.
| Symptom | Likely cause | First step |
|---|---|---|
| Hash Sum mismatch | The mirror is in the middle of a sync | Wait a little, then rerun apt update |
| 404 Not Found | The package is missing or the index is stale | Refresh the index, then try another mirror |
| NO_PUBKEY | The repository key is not on the system | Add the key after verifying it at the official source |
| Release file is not valid yet | The server clock is behind | Check time synchronisation |
Why does a mirror fall behind? Synchronisation runs at intervals, so packages that enter the main archive during that gap have not reached the mirror yet. Large mirrors shorten the gap with push triggers. A short mismatch is normal, so retrying first is reasonable.
The last row deserves attention. A wrong clock can make a signed index look invalid. We covered that topic in our NTP guide, so we will not repeat it here.
How do you prepare before changing the mirror setting?
Editing the source list changes your server's update path, so a mistake is costly. If you get it wrong, security patches stop arriving. So take a backup first, then verify the change in small steps. The commands below are an example for Ubuntu 24.04 and later, and the file name depends on your release.
sudo cp /etc/apt/sources.list.d/ubuntu.sources /root/ubuntu.sources.backup
sudo apt update
apt policy
sudo apt-get -s upgrade
The first command copies the file. apt update refreshes the indexes and prints the addresses it uses. apt policy shows where packages would come from. The -s flag on the last command means simulate, so it lists what would happen without installing anything.
If something breaks, however, going back is simple. Then copy the backup into place and run apt update again. Your server returns to the last known good configuration, and you can investigate calmly.
On RPM-based systems the equivalents are dnf makecache and dnf repolist. The output format can change with the dnf version. Check by eye that the address you expect appears, and only then move on to a real update.
How can updates be safe if you do not trust the mirror?
Security rests on signatures, not on the honesty of the mirror. The Debian SecureApt page describes the chain. Each package checksum sits in a Packages file, the checksums of the Packages files sit in the Release file, and a distribution OpenPGP signature protects the Release file.
When you run apt update, apt verifies that signature (Release.gpg or InRelease). If it cannot verify it, apt warns you and treats the packages as untrusted. The page also stresses that a mirror does not need separate trust, because the signature authenticates the content whichever mirror delivers it.
In practice, a stranger's mirror that alters a package breaks the checksum chain, and apt stops. You must still be careful when you add a key yourself, because the one weak point left is the key you decide to trust.
How do you check GPG verification in apt and dnf?
On the apt side, the setting is the Signed-By line. The official Debian and Ubuntu keyrings sit in /usr/share/keyrings/. The Debian wiki notes that the old /etc/apt/trusted.gpg and apt-key approach is deprecated as of Debian 13. So define a new key in a repository-specific file and reference it with Signed-By.
On the dnf side, gpgcheck verifies package signatures and repo_gpgcheck verifies repository metadata. The gpgkey option holds the address of the signing key. One detail matters: the dnf reference lists both gpgcheck and repo_gpgcheck as off by default. Distribution .repo files usually switch them on, but in a file you write by hand you must say so explicitly.
[example-internal]
name=Example internal mirror
baseurl=https://mirror.example.com/repo/example/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/EXAMPLE-GPG-KEY
Turn on repo_gpgcheck only if the upstream repository signs its metadata. Otherwise dnf reports an error. If you are unsure, read your distribution's documentation.
Does HTTP versus HTTPS matter for a mirror?
It does, but keep the two layers apart. A signature proves that a package did not change. HTTPS encrypts the transfer path. The example address in the Ubuntu documentation is http://archive.ubuntu.com/ubuntu, so integrity holds over plain HTTP thanks to the signed structure.
HTTPS, on the other hand, makes it harder for third parties on the network to see which packages you download. Some corporate networks also filter or rewrite HTTP traffic. For that reason we recommend choosing HTTPS whenever the mirror offers it.
If you publish your own mirror, an SSL certificate adds a little work but simplifies the decision on the client side. You can check that your certificate is valid with our SSL checker.
When does a private Linux package mirror make sense?
Running your own mirror pays off only when several conditions meet. For most websites and small stores, public mirrors are more than enough. An internal mirror creates value where package downloads are a real cost or risk for the organisation.
- Many servers download the same packages, and you want to protect outbound bandwidth.
- Servers cannot reach the internet directly, for example in a closed network behind a strict firewall.
- You want to freeze updates at a given date and run identical package versions in every environment.
- Your deployment pipeline has to keep working when an outside mirror is down.
Control is another side of a private Linux package mirror: you decide which package enters your network and when. That authority is valuable in closed networks and in strict compliance settings. However, the same authority makes you responsible for syncing updates on time.
So ask yourself one question: do you manage a single server or a fleet? For one VPS, an internal mirror usually creates more work than it saves.
Should you run a full mirror, a partial mirror or a caching proxy?
The three approaches serve different needs. Debian's documentation recommends the ftpsync tool for a full mirror. For organisations that only need certain releases, it describes debmirror as a good fit. A caching proxy is a separate path.
| Approach | Advantage | Drawback |
|---|---|---|
| Full mirror (ftpsync) | Every package and release is local | Needs large disks and regular syncing |
| Partial mirror (debmirror, reposync) | Only the releases and sections you pick | A package outside your selection fails |
| Caching proxy (apt-cacher-ng, squid, varnish) | Small disk, easy setup | The first download still comes from outside |
How much space does a full mirror need? Debian's documentation points to a separate mirror size page. Sizes change with every release, so we give no figure. In a partial mirror, the number of architectures and sections sets how fast the disk fills.
For most corporate networks, a partial mirror or a caching proxy is enough. A full mirror makes sense when the need is constant and broad.
How do you build a partial mirror for Debian and Ubuntu?
You can use debmirror for a partial mirror. The tool checks the signature of the index files against a local keyring. Therefore you must first import the distribution's official key into that keyring. The commands below are a short summary of the method on the man debmirror page.
sudo apt install debmirror debian-archive-keyring
gpg --no-default-keyring --keyring trustedkeys.gpg --import /usr/share/keyrings/debian-archive-keyring.gpg
debmirror --method=https --host=mirror.example.com --root=debian --dist=CODENAME --section=main --arch=amd64 /srv/mirror/debian
The first command installs the tool. The second imports the official key. Then the third command downloads the mirror for the release, section and architecture you chose into /srv/mirror/debian. In the host field, you write the source you picked from the official list instead of the example domain.
The idea is the same for Ubuntu, but the keyring and the directory path differ. Verify the options with man debmirror on your own release before you run anything. The first sync can be large, so read Debian's mirror documentation for sizes.
How do you build a mirror with reposync on RPM systems?
On the dnf side, the reposync plugin synchronises a remote repository to a local directory. The documentation says packages that are already present are not downloaded again. The plugin also ships in the dnf-plugins-core package, and you name the repository with --repoid.
sudo dnf install dnf-plugins-core createrepo_c
sudo dnf reposync --repoid=EXAMPLE-REPO --download-path=/srv/mirror --download-metadata --newest-only --gpgcheck
sudo createrepo_c --update /srv/mirror/EXAMPLE-REPO
With --download-metadata, the downloaded copy works as a repository right away. --newest-only fetches just the latest packages. --gpgcheck removes packages whose signature fails after download. In addition, the documentation suggests running createrepo_c --update together with --newest-only, so missing packages are dropped from the metadata.
In the last step, you publish the directory as static files through a web server such as nginx or Apache, and clients use that address as baseurl in their .repo file. The repository ID (EXAMPLE-REPO) has to be defined on the system beforehand.
How do you point client servers at an internal mirror?
Once the mirror is ready, you redirect clients one by one or through configuration management. On Debian and Ubuntu you change the URIs line in the sources file. On RPM-based systems you update the baseurl line in the .repo file.
- Back up the current configuration first.
- On one test server, switch the URIs or baseurl line to the internal address.
- Run apt update on Debian and Ubuntu, or dnf makecache on RPM systems, and confirm there are no errors.
- Make sure no signature warning appears; if one does, check the key.
- Then roll out to the other servers, starting with a small group.
Monitor the mirror as well. When a sync fails, clients stay on old packages and you may not notice. Security updates arrive as a separate channel, so make sure your mirror covers that channel too.
How do security updates behave when a mirror lags?
Distributions usually publish security fixes in a separate channel. If your mirror copies that channel, a delay equal to the sync interval appears. On public mirrors this interval is short. On your own mirror, you set the frequency.
For example, if you sync once a week, your clients may see a new security patch up to a week late in the worst case. If the patch is critical, that wait can be unacceptable. You could sync the security channel more often and the remaining channels less often.
In addition, if you have frozen releases on purpose, plan how you will receive security patches. A caching proxy alone avoids the issue, because patches flow straight from the distribution. For the wider server picture, see our CSF firewall guide as well.
What can you learn from Debian's mirror rules?
Debian asks operators who want to join its official mirror list to synchronise four times a day and to carry source files for the architectures they support. The same page describes push mirroring: an upstream mirror uses an SSH trigger to tell the downstream mirror to update itself. This way changes reach mirrors as quickly as possible.
For your own mirror, you can take three lessons from these details. First, sync frequency is a decision, not an accident. Second, updates must be written in the right order, which is why Debian recommends ftpsync over home-made rsync scripts. Third, any trigger or timer you set up needs monitoring too.
In short, a mirror is not a one-time installation. It is a service that you keep running.
What should you monitor once your own mirror is live?
A mirror is not a folder you set up once and forget. It can break quietly, and clients notice only when an update fails. So check a few simple signals on a schedule:
- The time of the last successful sync and the next planned run.
- Disk usage, because a sync stops halfway on a full disk.
- Rising 404 and 5xx errors in the web server log.
- The expiry date of your HTTPS certificate.
- Updates to the keyring package when the distribution rotates its signing key.
You can automate these checks with a scheduled job and an alert channel. Still, if nobody will actually read the alert, staying on a public mirror is the more honest choice than building your own.
When should you leave this to your hosting provider?
Not every mirror setting has to be your responsibility. In some cases the right call is to hand the job to your provider:
- On shared hosting or a cPanel account you have no root access, so you cannot and should not touch the package manager.
- On a managed VPS, changing the source list may affect your support coverage, so ask the provider first.
- Do not change the mirror on the server that runs your live store before you have tested it elsewhere.
- If you cannot set aside disk, monitoring and security patching for a mirror server, use a public mirror or a caching proxy.
Ask yourself one more question: if I get this wrong, who rescues the site? If the answer is the provider's support team, talking to them first is often the cheapest insurance. That is the cautious approach we recommend too.
Some providers run mirrors of their own. Read your provider's documentation and ask support about anything unclear. For the bigger infrastructure decision, see our guides on choosing web hosting and a website backup strategy.
Are there mirrors for Docker, pip and npm too?
Yes, the mirror idea is not limited to Linux packages. Developers also have similar cache and mirror options for the registries they use. The logic is the same: fetch dependencies from a nearby source that you can control.
For the container side, read our Docker guide. Package installs also run during image builds, so your mirror choice shows up in build time. Each tool has its own configuration file, though, so confirm command and setting names in that tool's official documentation.
The security concern stays the same. Whichever source you download from, keep signature or checksum verification switched on. Also, the component security section of our OWASP Top 10 article is a good place to start thinking about your dependency chain.
What is a short roadmap for your mirror decision?
To simplify the decision, follow this order. Each step depends on the one before it, so skipping steps makes your life harder.
- Find your current mirror address in the sources file or the .repo file.
- Measure your update time; if it is slow, try a nearby candidate from the official list.
- Confirm that signature verification is on (Signed-By, gpgcheck).
- If your server count and network limits call for it, think about a caching proxy first and a partial mirror second.
- When you build your own mirror, monitor syncing and disk usage.
- On shared hosting or a managed VPS, consult your provider.
To put the Linux package mirror in one sentence: a mirror improves speed and continuity, and the signature protects trust. For a small setup, a public mirror with signature checks on is often the best balance.
If you want to think about infrastructure together with your digital marketing goals, take a look at our web design service or contact us. You can also check your domain and DNS settings with our DNS lookup tool.
Sources: The technical details above rest on the official documents below. Commands and defaults may differ in your release, so always treat your own distribution's documentation as the first reference.
- Debian: Mirroring Debian (ftpsync, debmirror, push mirroring)
- Debian Wiki: SecureApt (signature chain)
- Debian Wiki: SourcesList (deb822 format)
- Ubuntu Server documentation: package management (ubuntu.sources)
- DNF configuration reference (baseurl, mirrorlist, metalink, gpgcheck)
- DNF reposync plugin



