sodcalculator

10 Tech How-To

Ubuntu Dependency Fix: Install & Repair Guide

Guide 10-28810 · Updated · Step by step

This guide walks you through installing software on Ubuntu and fixing the most common dependency errors, such as unmet dependencies, broken packages, and E: Unable to correct problems. You’ll learn the standard commands, how to repair a broken package manager state, and what to do when a package refuses to install.

What You’ll Need

  • A Ubuntu system (22.04, 24.04, or similar) with an internet connection.
  • A user account with sudo privileges (you’ll be prompted for your password).
  • Basic comfort with the terminal — you can open it with Ctrl+Alt+T.

Step-by-Step

  1. Update your package lists. Run sudo apt update. This refreshes the list of available packages and their dependencies from the repositories. If this fails with a network error, check your internet connection first.
  2. Upgrade installed packages. Run sudo apt upgrade. This brings all currently installed packages to their latest versions, which often resolves dependency mismatches caused by partial updates.
  3. Install the package normally. Use sudo apt install [package-name]. Replace [package-name] with the actual package, e.g., sudo apt install vlc. If it installs without errors, you’re done.
  4. If you see a dependency error, try fixing broken packages. Run sudo apt --fix-broken install. This command tells apt to correct any broken dependencies, often by installing missing packages or removing conflicting ones. Review the changes it proposes before confirming with Y.
  5. Clean up the package cache. Run sudo apt clean and then sudo apt autoclean. These remove downloaded package files that may be corrupted or incomplete, which can cause dependency issues.
  6. Reconfigure any partially configured packages. Run sudo dpkg --configure -a. This finishes any interrupted package configurations. It’s a common fix after a power loss or a crash during installation.
  7. If the error persists, try installing with the -f flag. Run sudo apt install -f [package-name]. This is an alias for --fix-broken and can be used directly with the install command.
  8. Check for held packages. Run apt-mark showhold. If a package is listed, it’s being held back from updates. You can unhold it with sudo apt-mark unhold [package-name], then try the install again.
  9. Consider using a different repository. If the package is not in the standard Ubuntu repositories, you may need to add a PPA or a third-party repository. Use sudo add-apt-repository ppa:some/ppa and then sudo apt update. Only use repositories you trust.
  10. As a last resort, remove and reinstall the package. Run sudo apt remove --purge [package-name] to completely remove the package and its configuration files, then sudo apt install [package-name] to install it fresh.

Common Mistakes

  • Mixing package managers. Using pip, npm, or snap to install software that should be managed by apt can create conflicts. Stick to one manager per package.
  • Ignoring the apt update step. Installing without updating first often leads to “package not found” or dependency errors because the package list is outdated.
  • Running apt upgrade instead of apt dist-upgrade. For major version upgrades, dist-upgrade handles dependency changes more aggressively, but it can also remove packages. Use it carefully.
  • Forgetting to review proposed changes. When apt asks to remove or install extra packages, always read the list. Blindly accepting can remove software you need.
  • Using sudo with pip. Installing Python packages with sudo pip can overwrite system files and break dependencies. Use a virtual environment instead.

Tips

  • Use apt instead of apt-get. The apt command is more user-friendly and provides better progress bars and messages.
  • Keep your system updated regularly. Run sudo apt update && sudo apt upgrade weekly to prevent dependency rot.
  • Read error messages carefully. They often tell you exactly which package is missing or conflicting.
  • Use apt-cache depends [package] to see a package’s dependencies before installing. This helps you anticipate issues.
  • If you’re trying to install a .deb file, use sudo apt install ./file.deb. This will automatically fetch and install dependencies from the repositories.

Troubleshooting

If the steps above don’t resolve the issue, try these targeted fixes:

  • Error: “E: Unmet dependencies. Try ‘apt –fix-broken install'” — Run sudo apt --fix-broken install first. If that fails, run sudo dpkg --configure -a and then sudo apt --fix-broken install again.
  • Error: “E: Could not get lock /var/lib/dpkg/lock” — Another process (like Software Updater) is using apt. Wait for it to finish, or close it. If it’s stuck, run sudo pkill apt and sudo pkill dpkg, then try again.
  • Error: “Package has no installation candidate” — The package is not in your repositories. Check the spelling, enable the universe repository with sudo add-apt-repository universe, or add a PPA.
  • Error: “The following packages have been kept back” — This is normal. Run sudo apt dist-upgrade to upgrade them, but be aware it may remove packages.
  • Error: “dpkg: error processing package …” — Try sudo dpkg --remove --force-remove-reinstreq [package] to remove a broken package, then reinstall it.
  • If nothing works, check for a system update. Run sudo do-release-upgrade to upgrade to a newer Ubuntu release, which may fix underlying dependency issues.

Frequently Asked Questions

What does “unmet dependencies” mean?

It means the package you’re trying to install requires another package (or a specific version) that isn’t installed or is too old. Apt tries to resolve this, but sometimes it can’t.

Can I force install a package ignoring dependencies?

Yes, with sudo apt install --ignore-missing [package], but this is risky. The package may not work correctly, and you could break other software. Only use it as a temporary measure.

What is the difference between apt and apt-get?

apt is a newer, more user-friendly front-end to apt-get. Both do the same thing, but apt has better output and some extra commands like apt list.

Why does apt sometimes want to remove packages I want to keep?

This happens when a package’s dependencies conflict with installed packages. Apt proposes a solution that removes the conflicting package to satisfy the new one. Review the list carefully before confirming.

How do I install a package from a .deb file?

Use sudo apt install ./package.deb (note the ./). This will install the package and automatically fetch its dependencies from the repositories.

What should I do if a PPA causes dependency issues?

Remove the PPA with sudo add-apt-repository --remove ppa:some/ppa, then run sudo apt update and sudo apt --fix-broken install to repair any damage.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →