Package Management Troubleshooting: Resolving Dependency Errors

Package Management Troubleshooting: Resolving Dependency Errors

What Are Dependency Errors?

Dependency errors occur when "Package A requires Package B, but B is missing or at an incompatible version." The root cause is almost always one of three things: a mismatched repository state, an interrupted installation, or conflicting third-party repositories.

Resolution strategy

  1. Refresh repo metadata first: apt update / dnf makecache
  2. Run auto-repair: apt --fix-broken install / dpkg --configure -a
  3. Only escalate to manual fixes if those don't work

apt Dependency Errors and Fixes

E: Unmet dependencies

E: Unmet dependencies.
Try 'apt --fix-broken install' with no packages (or specify a solution).

Missing dependency packages. Try in this order:

sudo apt --fix-broken install
Reading package lists... Done
Building dependency tree
Correcting dependencies... Done
The following packages will be installed:
  libfoo1
...

This auto-completes missing dependencies and finishes interrupted installs. Resolves most cases.

If that's not enough:

sudo dpkg --configure -a
sudo apt-get install -f

E: Unable to locate package

E: Unable to locate package foo

The package doesn't exist in your current repo lists.

# Refresh the package index first
sudo apt update
sudo apt install package-name

Running apt update before installing resolves the majority of "can't find package" errors caused by stale cache.

If the package is in the Universe repository (Ubuntu):

sudo add-apt-repository universe
sudo apt update
sudo apt install package-name

The following packages have been kept back

The following packages have been kept back: foo

The package needs a dependency change to upgrade — apt upgrade skips these.

# Install the held package directly
sudo apt install foo

# Or upgrade all held packages at once
sudo apt full-upgrade

Recovering from a Broken dpkg State

When dpkg is interrupted mid-operation (Ctrl+C, power loss, etc.), subsequent commands fail with:

dpkg was interrupted, you must manually run 'sudo dpkg --configure -a'
to correct the problem.

Recovery:

sudo dpkg --configure -a
Setting up libssl1.1:amd64 (1.1.1f-1ubuntu2.20) ...
Processing triggers for libc-bin (2.31-13+deb11u7) ...

If a specific package is still broken:

sudo dpkg --configure package-name

Force-remove and reinstall a stuck package:

sudo dpkg --remove --force-remove-reinstreq package-name
sudo apt install package-name

yum / dnf Dependency Errors

Transaction Check Error (file conflict)

Error: Transaction check error:
  file /path/to/file conflicts with file from package foo-1.0

A file on disk is already claimed by a different package.

# Check which package owns the conflicting file
rpm -qf /path/to/file
foo-1.0-1.el9.x86_64
# Remove the conflicting package, then install the target
sudo dnf remove conflicting-package
sudo dnf install target-package

Dependency problems (version mismatch)

Error: Problem: package foo-2.0 requires bar >= 2.0, but none of the providers can be installed
# Check what versions are available
dnf list --available bar

# Sync installed packages to current repo versions
sudo dnf distro-sync

dnf distro-sync aligns installed packages to the versions available in the active repositories. For yum environments, yum distro-sync works the same way.

If a third-party repo (e.g., EPEL) is causing the conflict:

# Disable the problematic repo temporarily
sudo dnf install package-name --disablerepo=epel

Repository Issues

GPG Key Errors

The following signatures were invalid: EXPKEYSIG XXXXXXXXXXXXXXXX

The repository's GPG signing key has expired.

# Ubuntu / Debian — reimport the key
curl -fsSL https://repo-key-url | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/repo.gpg
sudo apt update

# CentOS / Fedora — import the RPM key
sudo rpm --import https://repo-key-url

Lock File Conflicts

E: Could not get lock /var/lib/dpkg/lock-frontend

Another apt process is running, or a prior run crashed without releasing the lock.

# Check for running apt/dpkg processes
ps aux | grep -E "apt|dpkg"

If a process exists: wait for it to finish. Use sudo kill -9 PID only as a last resort.

If no process exists (crashed run):

sudo rm /var/lib/dpkg/lock-frontend
sudo rm /var/lib/dpkg/lock
sudo dpkg --configure -a

For yum / dnf locks:

# yum lock
sudo rm /var/run/yum.pid

# dnf lock
sudo rm /var/cache/dnf/*.lock

Diagnosis Flow

When you hit a dependency error, run through these steps in order:

Step Command Effect
1. Refresh cache apt update / dnf makecache Get current repo metadata
2. Auto-fix apt --fix-broken install Fill missing dependencies
3. Complete dpkg dpkg --configure -a Finish pending configurations
4. Force fix apt-get install -f Force dependency resolution
5. Sync dnf distro-sync Align packages to repo state

--force options are last resorts. Only consider them after steps 1–4 fail.

Next Reading