Skip to Content

Common Symptoms

  • apt install reports “dependency not satisfied”
  • dpkg is interrupted and cannot continue installation
  • “held broken packages” message appears
  • Package status is “half-installed” or “half-configured”
Note

Most package issues can be resolved with the first three steps (dpkg --configure -a, apt --fix-broken install, apt update && apt upgrade). Please try them in order and do not rush to use advanced repair methods.

Standard Repair Procedure

Try the following steps in order. The first few steps usually resolve the issue.

Step 1: Fix interrupted dpkg

sudo dpkg --configure -a

Step 2: Fix dependencies

sudo apt --fix-broken install

Step 3: Update and clean up

sudo apt update sudo apt upgrade sudo apt autoremove sudo apt autoclean

Advanced Repair

Force fix packages

# View problematic packages dpkg -l | grep -E "^..[^i ]" # Force reinstall a package sudo apt install --reinstall PACKAGE_NAME # Force remove a broken package sudo dpkg --remove --force-remove-reinstreq PACKAGE_NAME

Clear package cache

# Delete all downloaded package cache sudo apt clean # Delete only outdated packages sudo apt autoclean # Manual cleanup sudo rm /var/cache/apt/archives/*.deb sudo rm /var/cache/apt/archives/partial/*.deb

Fix dpkg lock

If you get “Unable to lock the administration directory”:

# Check if other apt/dpkg processes are running ps aux | grep -E "apt|dpkg" # If you confirm no other processes are running, delete the lock files sudo rm /var/lib/dpkg/lock-frontend sudo rm /var/lib/dpkg/lock sudo rm /var/cache/apt/archives/lock sudo dpkg --configure -a

Rebuild dpkg database

In extreme cases where the dpkg database is corrupted:

# Back up existing database sudo cp -r /var/lib/dpkg /var/lib/dpkg.backup # Restore the status file from the system's daily backup (status is dpkg's core database) ls -t /var/backups/dpkg.status.* # List available backup snapshots sudo cp /var/backups/dpkg.status.0 /var/lib/dpkg/status # .0 is newest; use an older snapshot if needed sudo dpkg --clear-avail sudo apt update

Dependency Conflict Troubleshooting

View package dependencies

# View dependencies of a package apt depends PACKAGE_NAME # View which packages depend on a package apt rdepends PACKAGE_NAME # Simulate installation to see conflicts apt install -s PACKAGE_NAME

Conflicts caused by PPAs

Third-party PPAs are a common source of dependency conflicts:

# List added PPAs grep -rh "^deb " /etc/apt/sources.list.d/ | sort # Disable a problematic PPA sudo add-apt-repository --remove ppa:xxx/yyy # Downgrade PPA-installed packages to official versions sudo apt install ppa-purge sudo ppa-purge ppa:xxx/yyy

Version hold conflicts

# View held packages apt-mark showhold # Unhold a package sudo apt-mark unhold PACKAGE_NAME

Snap Package Issues

# View snap status snap list # Fix snap sudo snap refresh # Reinstall a problematic snap sudo snap remove PACKAGE_NAME sudo snap install PACKAGE_NAME

Last Resort

If none of the above methods work, try:

# Completely reinstall the package management system (use with caution) sudo apt install --reinstall dpkg apt # Or use aptitude for interactive conflict resolution sudo apt install aptitude sudo aptitude install PACKAGE_NAME # aptitude will offer multiple solutions to choose from

Prevention Tips

  1. Avoid adding untrusted third-party PPAs
  2. Do not mix software sources from different Ubuntu versions
  3. Regularly run sudo apt update && sudo apt upgrade
  4. Use apt install -s to simulate installation and check for conflicts
  5. Keep system package versions consistent; avoid manually installing .deb files that override system packages
Last updated on