Package installs fail on Ubuntu and Debian for a handful of recurring reasons. This guide covers the most common apt errors and how to fix each without breaking the system further.
Before you start
- Root or sudo access.
- Copy the exact error message; each one points to a different fix below.
- Avoid deleting files under
/var/lib/dpkgexcept where described.
Could not get lock /var/lib/dpkg/lock-frontend
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1234 (unattended-upgr)Another package process is running, very often automatic updates shortly after boot. Wait for it:
ps -p 1234 -o pid,etime,cmdDo not kill it or delete lock files while it runs; interrupting dpkg mid-install is what causes broken packages. If the process listed no longer exists and the lock remains (rare, after a crash), the next step usually clears it.
dpkg was interrupted
E: dpkg was interrupted, you must manually run 'dpkg --configure -a' to correct the problem.Run exactly that:
dpkg --configure -aIt finishes configuring half-installed packages. Then apt -f install and apt update && apt upgrade.
Unmet dependencies and broken packages
The following packages have unmet dependencies ... E: Unable to correct problems, you have held broken packages.- Let apt try to repair the dependency tree:
apt --fix-broken install - Look for held packages that block upgrades:Unhold if appropriate:
apt-mark showholdapt-mark unhold package. - Mixed repositories are a common root cause: packages from a PPA or another release conflict with the base system. Check
/etc/apt/sources.listand/etc/apt/sources.list.d/for entries for the wrong release codename, and useapt policy packageto see where versions come from. - If one package's install script keeps failing, read its error in the output; fixing the cause (e.g. a stopped service, a full disk) and rerunning
dpkg --configure -ausually completes it.
Repository signature errors
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY ABCD1234The repository's signing key is missing or expired. Re-add the key from the vendor's official instructions into /etc/apt/keyrings/ and reference it with signed-by= in the source line. The old apt-key command is deprecated.
Release file not found / 404 errors
E: The repository 'http://... focal Release' does not have a Release file.- A PPA or vendor repo does not support your release: remove or disable that source file.
- Your release reached end of life: the archive moved to
old-releases.ubuntu.com. Upgrade to a supported release instead.
Not enough disk space
Installs fail with write errors when / or /boot is full. Clean up with apt clean and apt autoremove --purge (removes old kernels), then retry.
Check the system is healthy again
apt update && apt -s upgradeA simulated upgrade without errors means the package database is consistent. dpkg --audit should print nothing.
Troubleshooting
- Sub-process /usr/bin/dpkg returned an error code (1): scroll up for the package-specific error; that is the real problem.
- Hash Sum mismatch: a stale mirror or proxy cache. Run
apt clean,rm -rf /var/lib/apt/lists/*, thenapt update. - Temporary failure resolving archive.ubuntu.com: DNS or network problem on the server, not apt.
apt errors FAQ
Can I just delete the lock files?
Only when you are certain no apt/dpkg process is running. Deleting locks under an active install corrupts the package state.
apt or apt-get?
Both use the same system. apt is friendlier for interactive use; apt-get has a stable interface for scripts.
What about AlmaLinux?
dnf has equivalents: dnf clean all, dnf distro-sync and rpm --rebuilddb for a damaged RPM database.
