How to Fix ‘Failed to Fetch: Connection Timed Out’ During apt update in Ubuntu

Maintaining an Ubuntu desktop or server requires routinely running sudo apt update to synchronize repository indices and apply security patches. However, encountering repeated terminal failures displaying “W: Failed to fetch http://archive.ubuntu.com/ubuntu/… Connection timed out” or “E: Some index files failed to download” halts software maintenance. In the Debian and Ubuntu Advanced Package Tool (APT) architecture, the package manager initiates multiple concurrent HTTP/HTTPS requests to upstream distribution mirrors. If a regional archive mirror experiences downtime, an upstream Internet Service Provider drops TCP SYN packets, or your system attempts to route through broken IPv6 configurations, APT hangs until its socket timeout expires. This guide outlines how to switch to healthy mirrors, enforce IPv4 transport, and resolve DNS routing bottlenecks in Ubuntu.

Why Does apt update Fail with Connection Timed Out?

Unlike package verification errors caused by missing GPG keys, connection timeouts indicate transport-layer network failures. Common causes include:

  • Overloaded or Unresponsive Mirror Servers: The default Canonical country mirror (e.g. us.archive.ubuntu.com or gb.archive.ubuntu.com) experiencing high traffic loads or localized infrastructure downtime.
  • Broken IPv6 Routing: The local network interface receiving an IPv6 prefix that lacks functional internet routing, causing APT to wait for IPv6 timeouts before falling back to IPv4.
  • Local DNS Resolver Failures: The systemd-resolved service or local nameservers failing to resolve distribution hostnames quickly.
  • Corporate Firewalls and Proxy Filtering: Security appliances inspecting outbound port 80/443 traffic and dropping continuous package repository connections.

Method 1: Force APT to Use IPv4 Transport

In many residential and cloud hosting networks, half-configured IPv6 routes cause package managers to stall. Forcing IPv4 eliminates transport hangs instantly.

  1. Test a one-off update enforcing IPv4 mode directly in Terminal:
    sudo apt update -o Acquire::ForceIPv4=true
  2. If the repository index downloads smoothly without timing out, make this configuration permanent.
  3. Create a dedicated APT configuration file:
    echo 'Acquire::ForceIPv4 "true";' | sudo tee /etc/apt/apt.conf.d/99force-ipv4
  4. Verify standard package updates now default to stable IPv4 routing:
    sudo apt update

Method 2: Switch to the Main Canonical Archive Mirror

Regional country mirrors occasionally experience synchronization lags or localized outages. Switching to the global primary mirror restores availability.

  1. Back up your existing package sources list:
    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
  2. On Ubuntu 22.04 and earlier, update regional mirror prefixes using sed:
    sudo sed -i 's|http://[a-z]*.archive.ubuntu.com/ubuntu/|http://archive.ubuntu.com/ubuntu/|g' /etc/apt/sources.list
  3. Alternatively, point to a highly redundant global mirror such as Kernel.org:
    sudo sed -i 's|http://archive.ubuntu.com/ubuntu/|http://mirrors.kernel.org/ubuntu/|g' /etc/apt/sources.list
  4. On modern Ubuntu 24.04 installations utilizing /etc/apt/sources.list.d/ubuntu.sources, edit the file and replace the URIs: parameter with http://archive.ubuntu.com/ubuntu.
  5. Refresh repository metadata:
    sudo apt update

Method 3: Clear Corrupted APT List Metadata and Cache

Stale or partially downloaded archive index files can cause the package manager to attempt invalid mirror ranges.

  1. Remove partial and cached package lists:
    sudo rm -rf /var/lib/apt/lists/*
    sudo rm -rf /var/lib/apt/lists/partial/*
  2. Clean the local download archive cache:
    sudo apt clean
  3. Run a clean update to re-fetch pristine package indices from scratch:
    sudo apt update

Method 4: Configure Reliable Public DNS Nameservers

Slow or failing DNS lookups frequently simulate connection timeouts during high-concurrency repository queries.

  1. Inspect systemd-resolved DNS settings:
    resolvectl status
  2. If DNS lookups fail, edit the resolved configuration:
    sudo nano /etc/systemd/resolved.conf
  3. Uncomment the DNS= directive and assign reliable public resolvers:
    DNS=1.1.1.1 8.8.8.8
  4. Save the file (Ctrl + O, then Ctrl + X) and restart the resolver daemon:
    sudo systemctl restart systemd-resolved

Diagnostic Reference for APT Timeout Errors

Issue Category Diagnostic Command Permanent Resolution
IPv6 Route Stalls apt update -o Acquire::ForceIPv4=true Save Acquire::ForceIPv4 "true"; in /etc/apt/apt.conf.d/
Regional Mirror Outage curl -I http://archive.ubuntu.com Switch mirror URL to mirrors.kernel.org in sources
Corrupted Local Index ls -lh /var/lib/apt/lists/partial/ Purge /var/lib/apt/lists/* and update cleanly
DNS Latency resolvectl query archive.ubuntu.com Configure upstream resolvers in resolved.conf

Implementing these network transport and mirror configurations eliminates connection timeouts and ensures dependable package updates on Ubuntu.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.