APT errors stop updates and new installations on Ubuntu and Debian until they are cleared. This guide covers the errors people hit most often, what each one actually means, and the fix — starting with the safe options before anything destructive.
First, the Four Commands That Fix Most Problems
sudo apt update
sudo dpkg --configure -a
sudo apt --fix-broken install
sudo apt full-upgrade
Run them in this order and read the output of each. Most interrupted or half-finished installs are repaired here. If an error remains, find it below.
“Could not get lock /var/lib/dpkg/lock-frontend”
Another APT process is running — on a fresh server it is almost always the automatic security updates (unattended-upgrades) that start shortly after boot. Find out what holds the lock:
sudo lsof /var/lib/dpkg/lock-frontend
ps aux | grep -E 'apt|dpkg|unattended' | grep -v grep
Wait for it to finish — usually a few minutes. Deleting lock files while a real install is running can corrupt the package database. Only if no APT or dpkg process exists and the lock is left over from a crash:
sudo rm /var/lib/dpkg/lock-frontend /var/lib/dpkg/lock
sudo dpkg --configure -a
“dpkg was interrupted, you must manually run 'sudo dpkg --configure -a'”
A previous install was cut off, often by a dropped SSH session or a reboot mid-upgrade.
sudo dpkg --configure -a
sudo apt --fix-broken install
Run long upgrades inside tmux or screen to stop this happening again.
“Unable to locate package”
sudo apt update
apt search PACKAGE_NAME
The package list may be stale, the name may differ on your release, or the package may live in a component or repository you have not enabled (for example universe on Ubuntu, contrib on Debian).
“You have held broken packages” / unmet dependencies
apt-mark showhold
sudo apt --fix-broken install
sudo apt full-upgrade
Usually caused by a third-party repository built for a different release, or packages from two sources fighting. Check the repositories in /etc/apt/sources.list.d/ match your release (cat /etc/os-release).
“The following signatures couldn't be verified” / NO_PUBKEY
A repository’s signing key is missing or has been rotated. apt-key is deprecated and removed in current releases; the modern way is a key file per repository, referenced with signed-by:
curl -fsSL https://example.com/repo-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/example.gpg
echo "deb [signed-by=/etc/apt/keyrings/example.gpg] https://example.com/apt stable main" | sudo tee /etc/apt/sources.list.d/example.list
sudo apt update
Use the key URL and repository line from that project’s own installation instructions — the ones above are placeholders. Create /etc/apt/keyrings first with sudo install -d -m 0755 /etc/apt/keyrings if it does not exist.
“Repository ... does not have a Release file” / 404 Not Found
The repository entry names a release that repository does not provide — common after a distribution upgrade, or on an old release whose archives have moved. Check every file:
grep -rh ^deb /etc/apt/sources.list /etc/apt/sources.list.d/
Fix or disable the offending line. If your release is past end of life, upgrading is the real fix — see How to Upgrade Debian 11 to Debian 12.
“Unable to fetch some archives” / “Hash Sum mismatch”
sudo apt clean
sudo apt update
sudo apt install --fix-missing
Usually a temporary mirror problem or a stale cache. If it keeps happening with one mirror, switch deb.debian.org or your Ubuntu mirror in the sources file.
“No space left on device”
df -h
sudo apt clean
sudo apt autoremove --purge
sudo journalctl --vacuum-size=200M
Old kernels, the APT cache and logs are the usual culprits. More in How to Fix “No Space Left on Device”. If the server is simply too small for what it runs, a plan with more disk is the lasting fix — compare on the pricing page.
Removing a Problematic Third-Party Repository
sudo mv /etc/apt/sources.list.d/problem.list /root/
sudo apt update
Moving the file rather than deleting it lets you restore it later.
APT Seems to Hang
Check that the server can reach the mirrors (curl -I http://deb.debian.org), and whether it is waiting on IPv6 that does not work. Forcing IPv4 for one run tells you quickly: sudo apt -o Acquire::ForceIPv4=true update.
Habits That Prevent APT Problems
- Run
apt updatebefore installing or troubleshooting. - Do long upgrades inside
tmux, never across a flaky connection. - Add third-party repositories only from sources you trust, each with its own
signed-bykey. - Keep automatic security updates on — see How to Enable Automatic Security Updates.
- Stay on a supported release. Support dates for Ubuntu and Debian are on the Ubuntu VPS and Debian VPS pages.
Continue Reading
- How to Update and Upgrade Your Ubuntu or Debian VPS
- How to Use dnf on AlmaLinux and Rocky Linux
- Full Root Access VPS
Browse more articles in Troubleshooting & FAQ.