I used to get really frustrated every time I ran apt update or apt upgrade on my Ubuntu server. The process would hang for minutes, and downloads felt painfully slow. After some digging, I realized the default Ubuntu repositories were pointing to servers far away from my location. That’s when I discovered the magic of choosing a closer mirror—and it made a huge difference! In this guide, I’ll share several easy ways to find and apply the fastest Ubuntu mirror for your region, whether you’re in the US, Europe, Asia, or anywhere else.
By default, Ubuntu uses international repositories (archive.ubuntu.com). To improve download speeds, you should select a mirror geographically close to your server location. Below are backup steps and ready-to-use commands for various regions worldwide.
1. Backup the Original Configuration (Mandatory)
Run the appropriate command for your Ubuntu release.
Ubuntu 18.04 / 20.04 / 22.04
cd /etc/apt/ && cp sources.list sources.list.bakUbuntu 24.04 and later
cd /etc/apt/sources.list.d/ && cp ubuntu.sources ubuntu.sources.bak2. Quick Methods to Find and Apply the Fastest Mirror
Method A: Simple Country Code Replacement
Replace the country code in the default mirror URL with your own. The format is http://XX.archive.ubuntu.com/ubuntu/ where XX is your country code .
Examples:
United States
# Ubuntu 18-22
sed -i 's/us.archive.ubuntu.com/us.archive.ubuntu.com/g' /etc/apt/sources.list
# Ubuntu 24+
sed -i 's/us.archive.ubuntu.com/us.archive.ubuntu.com/g' /etc/apt/sources.list.d/ubuntu.sourcesGermany (Europe)
# Ubuntu 18-22
sed -i 's/archive.ubuntu.com/de.archive.ubuntu.com/g' /etc/apt/sources.list
# Ubuntu 24+
sed -i 's/archive.ubuntu.com/de.archive.ubuntu.com/g' /etc/apt/sources.list.d/ubuntu.sourcesAustralia
# Ubuntu 18-22
sed -i 's/archive.ubuntu.com/au.archive.ubuntu.com/g' /etc/apt/sources.list
# Ubuntu 24+
sed -i 's/archive.ubuntu.com/au.archive.ubuntu.com/g' /etc/apt/sources.list.d/ubuntu.sourcesSingapore (Southeast Asia)
# Ubuntu 18-22
sed -i 's/archive.ubuntu.com/sg.archive.ubuntu.com/g' /etc/apt/sources.list
# Ubuntu 24+
sed -i 's/archive.ubuntu.com/sg.archive.ubuntu.com/g' /etc/apt/sources.list.d/ubuntu.sourcesJapan
# Ubuntu 18-22
sed -i 's/archive.ubuntu.com/jp.archive.ubuntu.com/g' /etc/apt/sources.list
# Ubuntu 24+
sed -i 's/archive.ubuntu.com/jp.archive.ubuntu.com/g' /etc/apt/sources.list.d/ubuntu.sourcesMethod B: Use Mirror Protocol (Automatically Selects Country Mirror)
This method lets Ubuntu automatically select a mirror in your country .
Ubuntu 18-22
sed -i -e 's/http:\/\/.*archive.ubuntu.com\/ubuntu\//mirror:\/\/mirrors.ubuntu.com\/mirrors.txt/' /etc/apt/sources.listUbuntu 24+
# For Ubuntu 24+, manual editing is recommended as the sources format is different
# You'll need to replace the URIs line in ubuntu.sources with:
# URIs: mirror://mirrors.ubuntu.com/mirrors.txtMethod C: Using mirrorselect Tool (Recommended)
mirrorselect tests TCP latency and actual download speeds to find the fastest mirror .
Install mirrorselect
sudo snap install mirrorselectAuto-select fastest mirror for your location
sudo mirrorselectSelect fastest HTTPS mirror in the US
sudo mirrorselect --protocol https --country USSelect fastest mirror in Europe (Germany example)
sudo mirrorselect --country DESelect fastest mirror in Asia (Singapore)
sudo mirrorselect --country SGTest top 10 mirrors with custom timeout
sudo mirrorselect --max 10 --timeout 800Method D: Using faster-ubuntu-mirror Script
This bash script automatically tests and selects the fastest mirrors based on country codes .
Download and prepare the script
wget https://raw.githubusercontent.com/ezhkov-ph/faster-ubuntu-mirror/main/run.sh
chmod +x run.sh
sudo apt install wget bc # Install dependenciesAuto-select fastest mirror (recommended)
sudo ./run.sh -aSelect fastest mirror from specific countries
United States only:
sudo ./run.sh -c US -aEurope (Germany and France):
sudo ./run.sh -c DE FR -aAsia Pacific (Singapore, Japan, Australia):
sudo ./run.sh -c SG JP AU -aTest with larger file size for accuracy:
sudo ./run.sh -c US -s 500 -aSelect top 3 fastest mirrors from a region:
sudo ./run.sh -c DE -n 3 -aMethod E: Using mircheck (Python Tool)
Simple Python tool to find fastest mirrors .
Install
pip install mircheckFind fastest mirror for Ubuntu 22.04 (Jammy) in the US
mircheck jammy usFind fastest mirror in Germany and save to file
mircheck jammy de -o sources.list3. Verify and Update
After applying any method above, update your package lists:
sudo apt updateCheck download speeds with:
sudo apt upgrade --download-only # Tests download speed without installing4. List of Common Country Codes
| Country/Region | Code |
|---|---|
| United States | US |
| Canada | CA |
| United Kingdom | GB |
| Germany | DE |
| France | FR |
| Netherlands | NL |
| Australia | AU |
| Japan | JP |
| Singapore | SG |
| South Korea | KR |
| India | IN |
| Brazil | BR |
5. Restore Backup if Needed
Ubuntu 18-22
cp /etc/apt/sources.list.bak /etc/apt/sources.listUbuntu 24+
cp /etc/apt/sources.list.d/ubuntu.sources.bak /etc/apt/sources.list.d/ubuntu.sourcesChoose the method that best suits your needs. For most users, Method C (mirrorselect) or Method D (faster-ubuntu-mirror) provide the best automated results. For simple manual selection, use Method A with your country code.


