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.
Typical scenario
You update a VPS over SSH, the Wi-Fi drops in the middle of apt upgrade, and the session is gone. On the next try you get "dpkg was interrupted, you must manually run dpkg --configure -a". A kernel update may have been running. Before you repair anything, read with tail -n 40 /var/log/dpkg.log which package was processed last and in which state (unpacked or half-configured) it stands.
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.
How do I prevent a dropped SSH session from interrupting updates?
Run long operations in tmux or screen. If the connection drops, the session keeps running on the server and you reconnect later. Without that, a closed terminal can kill the program, and dpkg is left in a half-finished state.
Which log files show me what happened?
/var/log/dpkg.log contains every dpkg step with timestamp and state per package. /var/log/apt/term.log records the terminal output of apt runs, including errors from package scripts. Together they show at which package and in which step it stopped.
What do I do if dpkg --configure -a itself reports an error?
Read which package fails and why. dpkg --audit lists all packages in an incomplete state. If apt --fix-broken install does not help, you can, after careful checking, remove the package with dpkg --remove --force-remove-reinstreq package and install it again.