Fixing Package Dependency Conflicts on Ubuntu 22.04

Linux & Unix Beginner 👁 11 views 📅 Jun 28, 2026

Package dependency conflicts happen when apt can't resolve version mismatches between packages. Here's how to fix it fast.

Quick Fix (30 seconds)

You see something like "depends on libfoo2 but it's not installable" or "unmet dependencies"? The culprit is almost always a half-finished install or a bad repo. First, run this:

sudo apt --fix-broken install

This tells apt to fix any broken dependencies automatically. It'll try to install missing packages or remove ones that can't be fixed. If it works, you're done. If it spits out more errors, move to the next step.

Real-world trigger: You interrupted a sudo apt upgrade halfway through, or you installed a .deb package from a third-party site.

Moderate Fix (5 minutes)

If --fix-broken didn't work, you've got a deeper mess. Start by clearing the apt cache and updating the package list:

sudo apt clean
sudo apt update

Then try a targeted install of the problematic package with the -f flag:

sudo apt install -f package-name

Still failing? Check what's holding things up with:

sudo apt check

This shows you the exact list of broken packages. If you see something like "package-name depends on libsomething but it's not going to be installed", you can manually install that library first:

sudo apt install libsomething

Sometimes a package is just marked as "held back" due to a configuration issue. Force it with:

sudo apt-mark unhold package-name
sudo apt install package-name

Don't bother with dpkg --configure -a yet — that's for deeper corruption. Do it if the first two steps don't work, but it rarely helps here.

Remove and Reinstall

If the package is completely jacked, purge it and reinstall:

sudo apt purge package-name
sudo apt autoremove
sudo apt install package-name

This wipes the config files too. Be careful with system packages — don't purge apt itself.

Advanced Fix (15+ minutes)

Okay, nothing above worked. You've got a real dependency nightmare. Let's go nuclear.

Step 1: Check dpkg status

Look for packages in a bad state:

dpkg --audit

If you see packages marked as "rc" (removed but config files remain) or "iF" (half-installed), force configure them:

sudo dpkg --configure -a

This re-runs all post-install scripts. If it hangs, you might need to kill the process and manually fix the script.

Step 2: Manual dependency resolution

Grab the exact error message and search for the package versions. Use apt-cache to see what's available:

apt-cache policy package-name

If you see multiple versions, pin them manually. Edit or create /etc/apt/preferences.d/pinning and add:

Package: package-name
Pin: version 1.2.3-1
Pin-Priority: 1001

Then run sudo apt update && sudo apt install package-name.

Step 3: Remove and fix by hand (last resort)

If dpkg is refusing to install because of a dependency loop, you can remove the package database files and reinstall from scratch. But that's risky. Instead, use dpkg --remove on the broken package:

sudo dpkg --remove --force-depends package-name

Then reinstall it. If the package is critical (like libc6), don't do this — you'll break your system. In that case, boot into recovery mode or use a live USB.

Step 4: Check for held packages

Sometimes packages get marked as "hold" and block updates. Check with:

dpkg --get-selections | grep hold

Unhold them with sudo apt-mark unhold package-name then try again.

Prevention Tips

Three things to avoid this headache:

  1. Don't interrupt apt. Let it finish, even if it takes an hour.
  2. Use stable repos. Third-party PPAs break dependencies all the time. Stick to Ubuntu's official repos when you can.
  3. Pin versions for critical packages. If you need a specific version, pin it early.

And if you're on an older Ubuntu release (like 20.04), upgrade to 22.04 or 24.04 — the dependency resolver got way better.

Was this solution helpful?