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.
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
sudo dpkg --configure -asudo apt --fix-broken installsudo apt update && sudo apt upgradeIf the first command fails, read its last lines, which name the package that’s stuck.
1. Run it
sudo dpkg --configure -aThis 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:
sudo apt --fix-broken installsudo apt updatesudo apt upgrade2. If it says another process holds the lock
dpkg: error: dpkg frontend lock was locked by another process with pid 2143Something 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)df -h / /bootdf -i //boot is the usual culprit on Ubuntu, filling up with old kernels. Free space first, then run it again:
sudo apt cleansudo journalctl --vacuum-size=200Msudo apt autoremove --purgeIf 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 1Errors were encountered while processing: mypackageThat’s the key: the last lines name it, and post-installation script tells you where. Here, a service wouldn’t start. Read why:
sudo journalctl -xeu mypackage --no-pager | tail -n 30See 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:
sudo apt remove --purge mypackagesudo dpkg --configure -aIf apt won’t remove it, dpkg can:
sudo dpkg --remove --force-remove-reinstreq mypackageOnly 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 barTwo packages claim one file, often through a third-party repository. See which you have, and remove or update the one you don’t need:
dpkg -S /usr/bin/fooapt-cache policy foo bar6. Check the state
When it’s all done, this should print nothing:
sudo dpkg --auditdpkg -l | grep -vE '^(ii|rc)' | tail -n +6In 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.