This error occurs when a previous package installation was interrupted and left dpkg in an inconsistent state. Running `sudo dpkg --configure -a` recovers the system and allows updates to continue.
The dpkg package manager on Debian/Ubuntu systems maintains a lock file and internal state during package installations. When an installation is interrupted (due to power failure, network issues, manual termination, or a conflicting unattended-upgrades process), dpkg cannot proceed with new operations and refuses to install or remove packages until the interrupted state is resolved. The unattended-upgrades system detects this broken state and prevents further updates to avoid data corruption.
First, check if dpkg is actually in an interrupted state:
sudo apt-get updateThis will show you the exact error message and confirm the dpkg lock issue.
The primary fix is to run the dpkg configure command with the -a flag (configure all):
sudo dpkg --configure -aThis command unpacks and configures all packages that were left in an incomplete state. You may see prompts asking about configuration file changes—typically pressing Y or accepting defaults is safe.
After dpkg is repaired, refresh your package lists:
sudo apt-get updateThis downloads the latest package metadata from your configured repositories.
Fix any remaining package dependency issues:
sudo apt-get install -fThe -f flag stands for "fix" and will install missing dependencies or remove conflicting packages.
Now your system is ready for updates:
sudo apt-get upgradeor for a full distribution upgrade:
sudo apt-get dist-upgradeFor persistent issues where dpkg --configure -a fails repeatedly, check the dpkg log files: sudo cat /var/log/dpkg.log and sudo ls -la /var/log/unattended-upgrades/. If you see lock files that are stale, you can manually remove them as a last resort:
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock
sudo rm /var/lib/dpkg/lock-frontend
cd /var/lib/dpkg/updates
sudo rm *
sudo apt-get updateAlso check for hung processes: ps aux | grep apt and kill them if necessary with sudo kill -9 <PID> before retrying.
For unattended-upgrades specifically, you can enable automatic dpkg recovery by adding Unattended-Upgrade::AutoFixInterruptedDpkg "true"; to /etc/apt/apt.conf.d/50unattended-upgrades to prevent this issue in the future.
E: Could not connect to proxy server
Could not connect to proxy server
E: Package 'package:i386' has no installation candidate
How to fix "Package package:i386 has no installation candidate" in apt
E: The value 'value' is invalid for APT::Default-Release
How to fix invalid APT::Default-Release value in APT
dpkg: error: unable to create new file 'path': Permission denied
How to fix dpkg permission denied errors in APT
subprocess installed post-removal script returned error exit status 1
How to fix "subprocess installed post-removal script returned error exit status 1" in APT