Skip to content
ohsudo, Home
Linux

apt "dpkg was interrupted, you must manually run dpkg --configure -a": finish what was started

Fix apt "E: dpkg was interrupted, you must manually run sudo dpkg --configure -a": run it, then fix what stops it: a full disk, broken packages or a failing script.

Beginner3 min readApplies to Ubuntu · Debian · Linux Mint

by OhSudo ·

E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.

An installation or upgrade stopped partway: a closed terminal, a lost SSH connection, a reboot or a full disk. Some packages are unpacked, and aren’t set up yet, and apt refuses to do anything until that’s finished. The message tells you exactly what to run, and usually that’s all.

TL;DR

Terminal window
sudo dpkg --configure -a
sudo apt --fix-broken install
sudo apt update && sudo apt upgrade

If the first command fails, read its last lines, which name the package that’s stuck.

1. Run it

Terminal window
sudo dpkg --configure -a

This finishes setting up everything left half-done. It may take a while and print a lot, and it may ask you questions about config files. Let it finish. If you’re on SSH, use tmux, so a dropped connection can’t interrupt it again.

Then let apt finish what it planned:

Terminal window
sudo apt --fix-broken install
sudo apt update
sudo apt upgrade

2. If it says another process holds the lock

dpkg: error: dpkg frontend lock was locked by another process with pid 2143

Something else is working, often unattended-upgrades on a server. Wait for it, and don’t delete lock files. See could not get lock.

3. If the disk is full

A full disk is a common cause of the interruption itself, and running this again fails the same way:

dpkg: error processing archive ... (--unpack):
cannot copy extracted data for './usr/lib/...' to '...': failed to write (No space left on device)
Terminal window
df -h / /boot
df -i /

/boot is the usual culprit on Ubuntu, filling up with old kernels. Free space first, then run it again:

Terminal window
sudo apt clean
sudo journalctl --vacuum-size=200M
sudo apt autoremove --purge

If autoremove can’t run because of the broken state, list kernels with dpkg -l 'linux-image*'. Never remove the one you’re running, which uname -r shows. For more, see no space left on device.

4. A package that fails

Often one package’s own setup script is what fails:

Setting up mypackage (1.2.3) ...
Job for mypackage.service failed because the control process exited with error code.
dpkg: error processing package mypackage (--configure):
installed mypackage package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
mypackage

That’s the key: the last lines name it, and post-installation script tells you where. Here, a service wouldn’t start. Read why:

Terminal window
sudo journalctl -xeu mypackage --no-pager | tail -n 30

See Job for service failed. A service that already uses a port, or a broken config file, is common. Fix that, and run sudo dpkg --configure -a again.

Or if you don’t need it, remove it:

Terminal window
sudo apt remove --purge mypackage
sudo dpkg --configure -a

If apt won’t remove it, dpkg can:

Terminal window
sudo dpkg --remove --force-remove-reinstreq mypackage

Only use that for the one named package. Don’t use it on system packages such as libc6 or systemd.

5. Conflicts between files

dpkg: error processing archive /var/cache/apt/archives/foo.deb (--unpack):
trying to overwrite '/usr/bin/foo', which is also in package bar

Two packages claim one file, often through a third-party repository. See which you have, and remove or update the one you don’t need:

Terminal window
dpkg -S /usr/bin/foo
apt-cache policy foo bar

6. Check the state

When it’s all done, this should print nothing:

Terminal window
sudo dpkg --audit
dpkg -l | grep -vE '^(ii|rc)' | tail -n +6

In the second, ii means fine, and rc means removed with its config left behind. Anything else, like iU or iF, is half-finished.

If it happened during a release upgrade, don’t reboot yet, as the machine may not start: finish this, and check sudo do-release-upgrade afterwards.

Warning

Don’t delete things from /var/lib/dpkg/ to get past this, as forums sometimes suggest. That’s the record of what’s installed on your machine, and damaging it is much harder to fix than this error. Also avoid --force-all, which turns off every safety check. Take a snapshot first on a server, if you can.

Shell, we have a problem!

Similar, but different: Could not get lock means another process is running. Unable to locate package is about the package list. NO_PUBKEY is a repository’s key. You have held broken packages means that versions conflict, often after mixing repositories. If dpkg --configure -a itself stops with Sub-process /usr/bin/dpkg returned an error code (1), a package’s own script failed.

Found this useful? Share it.

Found a mistake? Let us know at contact@ohsudo.com.

Articles

Related articles