The 'W: Failed to fetch URL Connection timed out' warning appears when APT cannot download package metadata or files from repositories within the timeout period. This typically indicates network issues, slow mirrors, or temporary repository unavailability.
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.
Remove corrupted cache files that might be causing fetch failures:
# Clean APT cache
sudo apt clean
# Remove partial package lists
sudo rm -rf /var/lib/apt/lists/*
sudo mkdir -p /var/lib/apt/lists/partial
# Refresh package lists
sudo apt updateThe apt clean command deletes cached packages that may be incomplete or corrupted. Removing the entire lists directory forces APT to re-fetch all metadata from scratch.
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 mirror.example.com 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. Configure faster DNS servers:
# Edit resolv.conf
sudo nano /etc/resolv.confReplace the nameserver entries with public DNS servers:
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 1.1.1.1
nameserver 1.0.0.1To make this permanent (on systemd systems):
# Use systemd-resolved for DNS
sudo nano /etc/systemd/resolved.confAdd:
DNS=8.8.8.8 8.8.4.4 1.1.1.1 1.0.0.1
FallbackDNS=8.8.8.8 1.1.1.1Restart systemd-resolved:
sudo systemctl restart systemd-resolved
sudo apt updateIn 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
telnet archive.ubuntu.com 80
# Or use curl with verbose output
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, use:
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";
Dir::Cache::srcpkgcache "";The Queue-Mode "access" setting reduces parallel requests, which helps on slow connections. The srcpkgcache setting disables source package caching that can cause issues.
### 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