Troubleshooting

Fix apt errors: dpkg lock, interrupted installs and broken packages

Solve common apt and dpkg errors on Ubuntu and Debian: could not get lock, dpkg was interrupted, unmet dependencies, held packages and repository signature errors.

IntermediateLinux VPS3 min read

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/dpkg except 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,cmd

Do 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 -a

It 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.
  1. Let apt try to repair the dependency tree:
    apt --fix-broken install
  2. Look for held packages that block upgrades:
    apt-mark showhold
    Unhold if appropriate: apt-mark unhold package.
  3. Mixed repositories are a common root cause: packages from a PPA or another release conflict with the base system. Check /etc/apt/sources.list and /etc/apt/sources.list.d/ for entries for the wrong release codename, and use apt policy package to see where versions come from.
  4. 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 -a usually completes it.

Repository signature errors

The following signatures couldn't be verified because the public key is not available: NO_PUBKEY ABCD1234

The 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 upgrade

A 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/*, then apt 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.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.