In some cases, apt update may take a long time or hang on the following message:
0% [Waiting for headers]
This usually means that the server is waiting too long for a response from the current Ubuntu repository mirror. The most common reasons are a slow or overloaded mirror, network routing issues, DNS delays, IPv6 connectivity problems, or a temporarily unavailable repository server.
Replacing the default repositories with a stable alternative mirror, such as mirror.netcologne.de, can help improve package index download speed and make apt update complete reliably.
Ubuntu 22.04 LTS — Jammy
Replace /etc/apt/sources.list with the NetCologne mirror repositories:
cat > /etc/apt/sources.list <<'EOF'
deb https://mirror.netcologne.de/ubuntu/ jammy main restricted universe multiverse
deb https://mirror.netcologne.de/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirror.netcologne.de/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirror.netcologne.de/ubuntu/ jammy-security main restricted universe multiverse
EOF
Ubuntu 24.04 LTS — Noble
Replace /etc/apt/sources.list with the NetCologne mirror repositories:
cat > /etc/apt/sources.list <<'EOF'
deb https://mirror.netcologne.de/ubuntu/ noble main restricted universe multiverse
deb https://mirror.netcologne.de/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirror.netcologne.de/ubuntu/ noble-backports main restricted universe multiverse
deb https://mirror.netcologne.de/ubuntu/ noble-security main restricted universe multiverse
EOF
Remove duplicate Ubuntu source files if needed
If /etc/apt/sources.list.d/ contains additional Ubuntu repository files that cause duplicate repository warnings, remove all files from this directory without confirmation:
rm -f /etc/apt/sources.list.d/*
Clean old package lists and update indexes
apt clean
rm -rf /var/lib/apt/lists/*
apt update