Skip to main content

Package updates failing

## Why updates fail

When you run `apt update` or `yum update`, the package manager contacts remote repositories to download package lists and verify signatures. Several things can go wrong, and the error messages are not always self‑explanatory. Below are the most common causes for failed updates and how to fix them.

### Missing or expired GPG keys
If the error mentions a “NO_PUBKEY” or says that a repository is not signed, the package manager cannot verify packages from that source. This happens when a third‑party PPA has changed keys or when keys have expired.

- Obtain the missing key by running:
  ```
  sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <KEYID>
  sudo apt update
  ```
- For PPAs, consider removing the PPA or reinstalling the repository package that provides the key.
- On modern distributions, you may need to save the key in `/etc/apt/trusted.gpg.d/` instead of using `apt-key` which is deprecated.

### 404 Not Found or “release file does not exist”
A 404 error means the repository URL is wrong or the release is end of life. Ubuntu removes old release directories when they reach end‑of‑life, and third‑party PPAs can disappear.

- Check `/etc/apt/sources.list` and files under `/etc/apt/sources.list.d/` for typos or stale entries.
- If you are using an end‑of‑life Ubuntu version, switch to the `old-releases.ubuntu.com` mirror or upgrade to a supported release.
- Remove or disable PPAs that have been taken offline.

### Network or DNS problems
If the error mentions “Could not resolve”, “Failed to fetch” or times out, the machine cannot reach the repository.

- Verify general connectivity with `ping` or `curl`.
- Check `/etc/resolv.conf` to ensure that a valid nameserver is configured.
- If you use a proxy or firewall, make sure it permits outgoing HTTP/HTTPS traffic to the mirrors.

### Malformed or duplicate entries
Apt refuses to proceed if it detects duplicate or malformed lines in your sources lists.

- Open `/etc/apt/sources.list` and the files in `/etc/apt/sources.list.d/` and remove duplicate or invalid lines.
- On Ubuntu desktop you can use the `Software & Updates` GUI to clean up sources.
- After cleaning, run `sudo apt update` again.

### Hash sum mismatch or size mismatch
These errors occur when the package lists on disk don’t match the expected checksums.

- Clear the package lists and cache:
  ```
  sudo rm -rf /var/lib/apt/lists/*
  sudo apt clean
  sudo apt update
  ```
- Consider switching to another mirror if the problem persists; sometimes a mirror is out of sync.

### Package manager locked
If you see `E: Could not get lock` or “dpkg interrupted”, another process is using the package database.

- Wait a few minutes to let the other process finish.
- If no other apt process is running, remove the lock files:
  ```
  sudo rm /var/lib/dpkg/lock-frontend
  sudo rm /var/cache/apt/archives/lock
  sudo dpkg --configure -a
  ```
- Then run `sudo apt update` again.

## Best practices
- Keep your system on a supported distribution and regularly update.
- Avoid adding random PPAs; use official repositories whenever possible.
- Before editing your sources list, back it up.
- If you must use a custom mirror, choose one that is up‑to‑date and geographically close.