Troubleshooting Broken Packages
Broken packages on Ubuntu usually result from one of three things: an installation that was interrupted (power loss, Ctrl+C), a dependency conflict introduced by a third-party repository, or a partial upgrade where some packages updated and others did not. The good news is that most broken package situations have clear fixes that do not require reinstalling the OS.
Common apt error messages
| Error message | Cause |
|---|---|
dpkg was interrupted... run 'dpkg --configure -a' | Previous install/upgrade was interrupted |
E: Could not get lock /var/lib/dpkg/lock | Another apt/dpkg process is running |
E: Unmet dependencies. Try 'apt --fix-broken install' | Dependency conflict or incomplete install |
E: Package 'pkg' has no installation candidate | Package name wrong or repo not enabled |
E: 404 Not Found | Repository URL invalid or release EOL |
Sub-process /usr/bin/dpkg returned error code (1) | Post-install script failed |
Fixing dpkg interrupted or locked
Symptom:
E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.
Fix:
# Resume the interrupted installation
sudo dpkg --configure -a
# If that fails, try forcing the configuration
sudo dpkg --configure -a --force-confdef --force-confnew
Symptom:
E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock
Cause: Another apt process is running (unattended-upgrades, Software Updater).
Fix:
# Wait for the other process to finish (check what it is first)
ps aux | grep -E "apt|dpkg|unattended"
# If no process is actually running (stale lock), remove the lock files
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
sudo dpkg --configure -a
⚠️ WARNING: Never delete lock files while another apt/dpkg process is actually running. Deleting a live lock file can corrupt the dpkg database. Confirm with
ps aux | grep aptthat no apt process is genuinely active before removing locks.
Resolving dependency conflicts
Symptom:
E: Unmet dependencies.
nginx-core : Depends: libnginx-mod-http-image-filter (= 1.24.0-2) but 1.18.0-6 is installed
Fix:
# The standard fix: let apt resolve broken dependencies automatically
sudo apt --fix-broken install
# If that does not work, try aptitude which has a smarter resolver
sudo apt install aptitude
sudo aptitude install -f
# Manually specify which version to install
sudo apt install nginx-core=1.24.0-2 nginx=1.24.0-2
# Remove the conflicting package and reinstall
sudo apt remove nginx-core
sudo apt install nginx
Fixing held broken packages
# See if any packages are in a broken state
dpkg -l | grep -E "^(iU|iF|iH|rH|pH|tU|tF)"
# iU = installed but unpacked, iF = installed but half-configured
# Force-fix broken packages
sudo dpkg --configure -a
sudo apt --fix-broken install
# Check for packages with dependency problems
apt-get check
Recovering from a failed upgrade
If a dist-upgrade or release upgrade failed partway through:
# Step 1: Resume any interrupted package configurations
sudo dpkg --configure -a
# Step 2: Fix broken dependencies
sudo apt --fix-broken install
# Step 3: Update package lists
sudo apt update
# Step 4: Complete the upgrade
sudo apt upgrade
sudo apt full-upgrade
# Step 5: Clean up
sudo apt autoremove
# Step 6: Check for any remaining broken packages
dpkg -l | grep -E "^[^ii]" | grep -v "^rc" | head -20
Nuclear option: reinstalling a package
When a package’s post-install script is broken and nothing else works, reinstalling from scratch often resolves it:
# Force-reinstall a package (keeps config files)
sudo apt install --reinstall nginx
# Purge and reinstall (removes all config files — fresh start)
sudo apt purge nginx
sudo apt install nginx
# If the package refuses to install or remove, use dpkg --force
sudo dpkg --remove --force-all nginx
sudo apt install nginx
⚠️ WARNING:
dpkg --force-allbypasses all dependency checks and safety guards. Only use this as a last resort when standard removal is impossible, and only if you understand which packages depend on the one you are forcing. Using--force-allon a critical system library can break the entire system.
Conclusion
Broken packages follow a recovery sequence: dpkg --configure -a to resume interrupted configs, apt --fix-broken install to resolve dependencies, then apt upgrade to catch up. Most cases are resolved by these three commands in order. If not, check which package is the source of the conflict with dpkg -l | grep -v "^ii", and consider whether a third-party PPA or repository is introducing the conflict.
FAQ
Is Troubleshooting Broken Packages important for Ubuntu administrators?+
Yes. It supports practical Ubuntu administration because it connects directly to server reliability, security, troubleshooting, or daily operations.
Should I practice this on a live server?+
Use a lab VM first. After you understand the command output and rollback path, apply the workflow carefully on real systems.
What should I do after reading this article?+
Run the practice commands, write down what each one shows, and continue to the next article in the Ubuntu roadmap.
Need help with Ubuntu administration?
Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.
Hire Me for Support