What the message looks like
$ sudo apt upgrade
E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.Common causes
- The previous apt or dpkg run was cut off: SSH session lost, reboot, power loss or a killed process.
- A package script (postinst) failed, so the package stayed in a half-configured state.
- The disk or
/varran full during the installation. - Unattended upgrades were interrupted by a shutdown.
Check
- Is apt or dpkg still running? If yes, wait for it.
ps -eo pid,etime,cmd | grep -E '[a]pt|[d]pkg' - Which packages are in a broken state?
sudo dpkg --audit - Is there free space?
df -h / /var /boot - What happened in the last run?
tail -n 30 /var/log/dpkg.log
Fix
- Make sure no apt or dpkg process is running. Never delete the lock files while one is.
- Finish the interrupted work:
sudo dpkg --configure -a. - Then repair dependencies:
sudo apt --fix-broken install. - If one package keeps failing, read its error. Free disk space first if the disk was full, then repeat the two commands.
- Last resort for one package that cannot be configured: remove it with
sudo dpkg --remove --force-remove-reinstreq PACKAGEand install it again. Be careful with system packages.
FAQ
Can I just delete the lock file?
No. The message is not about a lock. Run dpkg --configure -a. Deleting locks while a process works can corrupt the package database.
Is it safe to run dpkg --configure -a on a production server?
Yes, it only finishes what was started. Check free space first, and run it in a screen or tmux session so a lost connection does not interrupt it again.