Fix apt that will not update

We'll confirm the error, check network and DNS, verify sources.list, fix repository URLs, and resolve lock issues so apt update succeeds.

Category
Troubleshooting · Servers & Linux
Time
10–20 min
Last reviewed
What you'll need
  • SSH or shell access with sudo
  • Root or sudo privileges

Step-by-step diagnostic

Step 1 of 9
Show full guide

Steps

Goal: Confirm the error, check network and DNS, verify sources.list, then fix repository or lock issues.

  • Run sudo apt update and capture the full output. Common errors: “Could not resolve” (DNS/network), “404 Not Found” (bad repository URL), “Unable to acquire the dpkg frontend lock” (another process or stale lock).
  • Good: You have the error. Proceed to Check network or Verify sources.list based on the error.

Check network

Goal: Rule out network and DNS as causes of apt update failure.

  • Run ping -c 3 archive.ubuntu.com (Ubuntu) or ping -c 3 deb.debian.org (Debian). If ping fails, check ip route and ip addr for interface state.
  • Run getent hosts archive.ubuntu.com or nslookup archive.ubuntu.com. If resolution fails, check /etc/resolv.conf for valid nameservers.
  • Good: Ping and DNS work—check sources.list and proxy. Bad: Fix network or DNS before retrying apt.

Verify sources.list

Goal: Confirm repository URLs and release names are correct.

  • Check /etc/apt/sources.list and files in /etc/apt/sources.list.d/. Look for typos in URLs, wrong release codenames (e.g. jammy for Ubuntu 22.04), or disabled lines.
  • Run lsb_release -cs to get the correct codename. Update any line that uses a wrong codename.
  • Good: Entries are valid. Retry apt update. Bad: Fix or comment out invalid entries.

Fix repository 404

Goal: Correct a repository URL or release name that causes 404.

  • When apt reports “404 Not Found” for a repository, the URL or release name is wrong. Check your release with lsb_release -cs.
  • Update the sources.list line to use the correct codename and mirror. Comment out third-party repos that no longer exist.
  • Retry sudo apt update. Confirm the repository succeeds.

Resolve lock

Goal: Clear a stale dpkg lock or wait for a running apt process.

  • Run ps aux | grep -E "apt|dpkg" to find running processes. If a legitimate process is running, wait for it to finish.
  • If a process crashed, run sudo rm /var/lib/dpkg/lock-frontend /var/lib/dpkg/lock and sudo dpkg --configure -a. Retry apt update.

Check proxy and firewall

Goal: Confirm proxy and firewall are not blocking apt.

  • When the server uses a proxy, set http_proxy and https_proxy or configure in /etc/apt/apt.conf.d/.
  • Confirm the firewall allows outbound HTTPS (443) to the repository hosts.

When to escalate

  • The repository mirror may be down—try a different mirror in sources.list.
  • Corporate proxy or custom repo—when to call a pro or contact your administrator.

Verification

  • sudo apt update completes without error.
  • Output shows “Reading package lists… Done” and either “All packages are up to date” or a list of upgradable packages.
  • No “Could not resolve”, “404”, or lock errors.

Escalation ladder

Work from the device outward. Stop when the problem is fixed.

  1. Confirm error Run apt update and capture the exact error message.
  2. Network and DNS Check connectivity and DNS; fix if broken.
  3. sources.list Verify repository URLs and release names; fix 404s.
  4. Lock and proxy Resolve dpkg lock; check proxy and firewall.
  5. Escalate Mirror down or custom repo—try different mirror or contact administrator.

What to capture if you need help

Before calling support or posting for help, have these ready. It speeds everything up.

  • Full apt update output
  • Output of ping and getent/nslookup
  • Contents of /etc/apt/sources.list and sources.list.d/
  • Output of lsb_release -cs
  • Steps already tried

Does the error mention network or resolve?

Errors like "Could not resolve" or "Temporary failure resolving" point to network or DNS.

Run `sudo apt update` and check the error. Good: error mentions resolve, connection, or network—proceed to network check. Bad: error mentions 404, lock, or repository—proceed to the matching path.

You can change your answer later.

Can you ping the repository host?

Test connectivity to archive.ubuntu.com or deb.debian.org.

Run `ping -c 3 archive.ubuntu.com` (Ubuntu) or `ping -c 3 deb.debian.org` (Debian). Good: ping succeeds—check DNS with getent hosts. Bad: ping fails—fix network (routes, interface, firewall) before retrying apt.

You can change your answer later.

Does DNS resolve the repository host?

Run getent hosts archive.ubuntu.com or nslookup.

Run `getent hosts archive.ubuntu.com`. Good: returns IP—network path is fine; check proxy/firewall or sources.list. Bad: no result—fix /etc/resolv.conf and nameservers.

You can change your answer later.

Fix network and retry

Check ip route, ip addr, and firewall. Fix connectivity. Retry apt update.

Fix DNS and retry

Edit /etc/resolv.conf with valid nameservers (e.g. 8.8.8.8). Retry apt update.

Is it a 404 or a lock error?

404 = bad repository URL. Lock = another apt/dpkg process or stale lock.

Check the error text. 404: repository URL or release name wrong—verify sources.list and lsb_release -cs. Lock: another process or stale lock—wait or remove lock files and run dpkg --configure -a.

You can change your answer later.

Fix sources.list and retry

Edit /etc/apt/sources.list and sources.list.d/. Fix wrong URLs or release codenames. Run lsb_release -cs to get correct codename. Retry apt update.

Resolve lock and retry

Check for running apt/dpkg with ps aux. If none, remove lock: sudo rm /var/lib/dpkg/lock-frontend /var/lib/dpkg/lock. Run sudo dpkg --configure -a. Retry apt update.

Are sources.list entries correct?

404 or repository errors mean wrong URL or release.

Check /etc/apt/sources.list and sources.list.d/. Fix typos, wrong URLs, or wrong release names. Run lsb_release -cs to confirm codename. Retry apt update.