Fixing Package Dependency Conflicts on Ubuntu 22.04
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 installThis 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 updateThen try a targeted install of the problematic package with the -f flag:
sudo apt install -f package-nameStill failing? Check what's holding things up with:
sudo apt checkThis 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 libsomethingSometimes 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-nameDon'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-nameThis 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 --auditIf you see packages marked as "rc" (removed but config files remain) or "iF" (half-installed), force configure them:
sudo dpkg --configure -aThis 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-nameIf 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: 1001Then 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-nameThen 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 holdUnhold them with sudo apt-mark unhold package-name then try again.
Prevention Tips
Three things to avoid this headache:
- Don't interrupt apt. Let it finish, even if it takes an hour.
- Use stable repos. Third-party PPAs break dependencies all the time. Stick to Ubuntu's official repos when you can.
- 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?