The 'W: Failed to fetch URL Connection timed out' warning appears when APT cannot reach a repository within its timeout, usually due to network issues, slow or dead mirrors, or DNS problems.
The "W: Failed to fetch URL Connection timed out" warning in APT indicates that the package manager attempted to connect to a repository server but the connection took longer than the configured timeout value. APT uses this timeout to prevent the update process from hanging indefinitely on unreachable servers. This warning typically appears during `apt update` or `apt install` operations when APT tries to fetch package lists, metadata, or actual package files from a mirror server. While APT can usually continue with other mirrors or retries, repeated timeout warnings suggest network instability or that the configured mirror is slow or unreachable. The error includes the full URL of the repository that timed out, which helps identify whether the issue is with a specific mirror or affects all repositories globally.
First, verify that your system has basic network connectivity:
# Test connectivity to a public DNS
ping -c 3 8.8.8.8
# Test connectivity to a major site
ping -c 3 google.com
# Test HTTPS connectivity to a repository
curl -v https://archive.ubuntu.com/ubuntu/dists/jammy/ReleaseIf these basic tests fail, the issue is with your network connection rather than APT specifically.
Corrupted or partial cache files can cause fetch failures. Start with the gentle, non-destructive cleanup and re-run the update:
# Remove cached .deb files (safe, packages re-download as needed)
sudo apt clean
# Refresh package lists
sudo apt updateIf apt update still fails after apt clean, escalate to clearing the downloaded package lists so APT re-fetches all metadata from scratch:
# Remove cached package lists (forces a full metadata refresh)
sudo rm -rf /var/lib/apt/lists/*
sudo mkdir -p /var/lib/apt/lists/partial
sudo apt updateDelete the lists directory only as a second step; apt clean alone resolves most cache-related fetch problems.
The default mirror may be slow or geographically distant. Select a mirror closer to your location:
# Edit sources.list
sudo nano /etc/apt/sources.listReplace the mirror domain with a faster alternative. For example, if using Ubuntu:
- Change archive.ubuntu.com to your country code mirror: us.archive.ubuntu.com, eu.archive.ubuntu.com, etc.
- Or try a mirror from your ISP or local mirror service
For Debian, check https://www.debian.org/mirror/list for nearby mirrors.
Save and try updating:
sudo apt updateIf you're unsure which mirror to choose, test connectivity first:
# Test a specific mirror
curl -I https://us.archive.ubuntu.com/ubuntu/Configure APT to wait longer before timing out connections:
# Create a timeout configuration
sudo nano /etc/apt/apt.conf.d/99timeoutAdd these lines to increase timeout values:
Acquire::http::Timeout "300";
Acquire::https::Timeout "300";
Acquire::ftp::Timeout "300";
Acquire::Retries "3";These settings give APT 5 minutes (300 seconds) to establish connections and retry up to 3 times. Save and test:
sudo apt updateAdjust the timeout value (in seconds) based on your network speed. For slow connections, 600 seconds (10 minutes) may be appropriate.
Slow or unreliable DNS can cause timeout errors. On modern Ubuntu and Debian systems, /etc/resolv.conf is usually a managed symlink (to systemd-resolved or NetworkManager) that gets regenerated on the next reboot or network change. Editing it directly is non-persistent, so configure DNS through the resolver service first.
Persistent fix (systemd-resolved):
# Edit the systemd-resolved configuration
sudo nano /etc/systemd/resolved.confUnder the [Resolve] section, set:
DNS=8.8.8.8 8.8.4.4 1.1.1.1 1.0.0.1
FallbackDNS=9.9.9.9Restart the service so the change takes effect, then test:
sudo systemctl restart systemd-resolved
sudo apt updateVerify the active resolvers with resolvectl status.
If your system manages DNS through NetworkManager, set the DNS on the active connection instead so it survives reboots:
sudo nmcli connection modify "<connection-name>" ipv4.dns "8.8.8.8 1.1.1.1"
sudo nmcli connection modify "<connection-name>" ipv4.ignore-auto-dns yes
sudo nmcli connection up "<connection-name>"Temporary test only (non-persistent): On a system without a DNS manager (or just to confirm DNS is the culprit before applying a persistent fix), you can edit /etc/resolv.conf directly. Be aware this is overwritten on the next reboot or network change:
sudo nano /etc/resolv.confnameserver 8.8.8.8
nameserver 1.1.1.1If this resolves the timeouts, apply the persistent method above to make it stick.
In some environments, IPv6 connectivity is broken or slower than IPv4. Force APT to use only IPv4:
# One-time IPv4-only update
sudo apt -o Acquire::ForceIPv4=true updateTo make this permanent:
# Create APT configuration
sudo nano /etc/apt/apt.conf.d/99force-ipv4Add:
Acquire::ForceIPv4 "true";Save and test:
sudo apt updateIf you're behind a corporate firewall or proxy, ensure APT can connect:
# Test connection to repository directly
curl -v http://archive.ubuntu.com/ubuntu/dists/jammy/ReleaseIf connections are blocked, configure your proxy:
# Create proxy configuration
sudo nano /etc/apt/apt.conf.d/99proxyAdd your proxy settings:
Acquire::http::Proxy "http://proxy.example.com:8080";
Acquire::https::Proxy "http://proxy.example.com:8080";Then test:
sudo apt updateFor authenticated proxies, embedding credentials in the URL writes them in plaintext to a world-readable config file. Prefer to keep credentials out of the URL where possible; if you must use them, restrict permissions on the file (sudo chmod 600 /etc/apt/apt.conf.d/99proxy):
Acquire::http::Proxy "http://username:[email protected]:8080";Check that your sources.list contains valid repository URLs that haven't been deprecated:
# View current sources
cat /etc/apt/sources.list
ls -la /etc/apt/sources.list.d/Look for:
- Outdated domain names (e.g., old Ubuntu release mirrors)
- Typos in URLs
- Repositories that no longer exist
For Ubuntu LTS releases that have reached end-of-life, archive mirrors may be required:
# For end-of-life Ubuntu releases
sudo sed -i 's/archive.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
sudo sed -i 's/security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
sudo apt updateFor currently supported releases, verify you're using the correct mirror URLs from the official Ubuntu or Debian mirror lists.
Enable verbose logging to see exactly where the timeout is occurring:
# Run apt update with debug output
sudo apt update -V
# Or with even more verbose output
sudo apt -o Debug::Acquire::http=true updateThe verbose output shows:
- Which specific URLs are timing out
- How long each connection attempt takes
- Which mirrors succeed and which fail
This helps identify if the issue is with a specific mirror or all mirrors. If only one mirror times out while others work, consider removing that mirror from your sources.list.
### Handling Intermittent Timeouts
If timeouts occur sporadically, the issue may be transient (temporary network fluctuations, server load spikes, etc.). APT is configured to retry, so you can:
# Retry the update multiple times
for i in {1..3}; do
sudo apt update && break
sleep 5
done### Repository-Specific Timeouts
If only certain repositories timeout while others work fine, you have two options:
1. Temporarily disable the problematic repository:
# Comment out lines in sources.list
sudo nano /etc/apt/sources.list.d/problematic-repo.list
# Or use: sudo add-apt-repository --remove ppa:username/ppa2. Switch that repository to a different mirror if available
### WSL2 (Windows Subsystem for Linux) Specific Issues
On WSL2, DNS resolution can degrade over time, causing timeouts:
# In PowerShell as Administrator
wsl --shutdownThen restart WSL and try apt update again.
### Performance Tuning for Slow Networks
For systems on very slow or unreliable connections:
# Create comprehensive timeout configuration
sudo nano /etc/apt/apt.conf.d/99-slow-networkAdd:
Acquire::http::Timeout "600";
Acquire::https::Timeout "600";
Acquire::ftp::Timeout "600";
Acquire::Retries "5";
Acquire::Queue-Mode "access";The Queue-Mode "access" setting reduces parallel requests, which helps on slow connections.
### Monitoring APT Timeout Issues
Keep track of which repositories cause timeouts:
# Save update output to a log file
sudo apt update 2>&1 | tee /tmp/apt-update.log
# Search for timeout errors
grep -i timeout /tmp/apt-update.logIf you see patterns (e.g., same mirror always times out), investigate that mirror specifically.
E: Could not connect to proxy server
Could not connect to proxy server
E: Package 'package:i386' has no installation candidate
How to fix "Package package:i386 has no installation candidate" in apt
E: The value 'value' is invalid for APT::Default-Release
How to fix invalid APT::Default-Release value in APT
dpkg: error: unable to create new file 'path': Permission denied
How to fix dpkg permission denied errors in APT
subprocess installed post-removal script returned error exit status 1
How to fix "subprocess installed post-removal script returned error exit status 1" in APT