How to Resolve Unmet Dependencies Error on Ubuntu

Using APT to manage software on Ubuntu (or similar Linux systems) is generally simple. It streamlines installing, removing, and updating packages.

However, third-party software can sometimes introduce complexities, leading to “unmet dependencies” errors that halt installations. This article offers solutions to this common problem.

Before attempting any fixes, back up your APT configuration files. This precaution allows you to restore your system if any changes cause problems. The essential files to back up are:

  • /etc/apt/sources.list: This file lists your software repositories.
  • /var/lib/dpkg/status: This file contains the status of installed packages.

1 Using Aptitude

While apt-get is a common tool for managing packages on Ubuntu and other Debian-based systems, aptitude offers a more powerful and user-friendly alternative. Aptitude provides a higher-level interface for visualizing dependencies, including suggested and recommended packages. It also excels at resolving package conflicts and presenting various solutions for installing, upgrading, or removing packages to fix issues.

Installing Aptitude:

To install aptitude, open your terminal and run the following command:

sudo apt-get install aptitude

Press Enter to confirm the installation.

sudo aptitude install PACKAGENAME

Replace PACKAGENAME with the actual name of the package you want to install. Aptitude will resolve any dependencies automatically, suggesting alternative solutions if conflicts arise.

Read: How to keep Ubuntu clean

2 – Cleaning up Package database

A corrupted package database or improperly installed packages can also trigger “Unmet Dependencies” errors on Ubuntu and Debian-based systems. Cleaning the APT cache can often resolve these issues. There are two main commands for cleaning the cache:

1. sudo apt-get clean:

This command removes downloaded package files (.deb files) from the local cache (/var/cache/apt/archives). It keeps lock files but removes everything else, freeing up disk space.

sudo apt-get clean

2. sudo apt-get autoclean:

This command removes only outdated package files that are no longer available in the configured repositories. This is a more conservative approach than clean, as it only removes packages that are definitely no longer needed.

sudo apt-get autoclean

After cleaning the cache, try installing the desired package again using sudo apt install PACKAGENAME or sudo aptitude install PACKAGENAME. The fresh package information may resolve the dependency issues.

3 Broadening Software Options in Ubuntu: How to Enable Restricted and Universe Repositories

Press Alt + F2 simultaneously. This opens the “Run Command” dialog. Type software-properties-gtk into the dialog box. This is the command that launches the Software & Updates utility.

Press Enter or click “Run.” The Software & Updates window will appear, allowing you to manage your software sources.

Navigate to the “Ubuntu Software” Tab: Once the Software & Updates window opens, click on the “Ubuntu Software” tab. This tab displays the various software sources available to your system.

Enable All Repositories: Ensure the following repositories have checkmarks next to them:

  • Main: Officially supported free and open-source software.
  • Restricted: Proprietary drivers for devices.
  • Universe: Community-maintained free and open-source software.
  • Multiverse: Software restricted by copyright or legal issues.

Apply Changes (If Necessary): If you made any changes, click the “Close” button. You’ll likely be prompted to reload the package information. Click “Reload” to update your system with the newly enabled repositories.

Next to the “Download from” label, you’ll see a dropdown menu currently displaying the selected server (often “Main Server”). Click on this dropdown menu to reveal a list of alternative server locations.

From the list of available servers, click the button labeled “Select Best Server.” Ubuntu will then automatically test the connection speed to various servers.

Ubuntu will take a few moments to test the available servers. A progress bar will indicate the testing process.

Once the test is complete, Ubuntu will automatically select the server with the fastest connection speed. Click “Choose Server” to confirm and apply the new setting.

Now in your terminal, type :

sudo apt-get update

Try installing the package again using either apt or aptitude.

4 Using the -f parameter

A quick way to fix broken dependencies in Ubuntu is by using the -f (or –fix-broken) flag with the apt-get install command. This flag instructs APT to attempt to correct any broken dependencies before proceeding with the installation.

Running the Command:

Instead of running the standard install command:

sudo apt-get install <package_name>

Use the following command with the -f flag:

sudo apt-get install -f

Afterwards, type :
sudo dpkg –-configure -a

If the output of the sudo apt-get install -f command shows:

0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.

This indicates that the command did not fully resolve the dependency issues. The “1 not upgraded” part suggests that a package couldn’t be fixed.

In this case, try running the sudo apt-get install -f command again:

sudo apt-get install -f

Read: How to speed up Linux

5 Removing On-hold packages

Sometimes, APT encounters dependency conflicts that it cannot automatically resolve. This can result in packages being placed in an “on-hold” state, meaning they are not fully installed and can block other installations. Removing these held packages might clear the conflicts and allow you to install the desired software.

Using dist-upgrade:

The dist-upgrade command is a more powerful version of upgrade. It can handle complex dependency changes, including removing held packages if necessary. To use it, open a terminal and enter the following command:

sudo apt-get -u dist-upgrade

The -u flag (or –show-upgraded) shows you a list of packages that will be upgraded before the upgrade actually happens, giving you a chance to review the changes.

Caution: dist-upgrade can significantly change your system, including removing existing packages. It’s generally safe, but reviewing the proposed changes beforehand is a good practice.

If the standard dist-upgrade command doesn’t resolve your dependency issues, you can use a debugging option to get more information and potentially fix the problem. This involves running dist-upgrade with a special flag to activate the package problem resolver’s debug mode.

Running dist-upgrade in Debug Mode:

Open your terminal and run the following command:

sudo apt-get -o Debug::pkgProblemResolver=yes dist-upgrade

If the dist-upgrade command, even with debugging enabled, still can’t resolve your dependency issues and you see output like:

0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.

It indicates that some packages remain held. You might need to remove these held packages individually to resolve the conflicts.Review the output of the previous dist-upgrade command to identify the specific packages held.

Before actually removing a package, use the –dry-run option to preview the consequences of the removal. This will show you which other packages would be affected without making any changes.

sudo apt-get remove –dry-run <package_name>

6 Remove/Disable/Purge PPAs

Personal Package Archives (PPAs) are software repositories hosted on Launchpad that provide access to packages not included in the official Ubuntu repositories. While useful, PPAs can sometimes cause unmet dependency errors, especially when they provide updates to packages that already exist in the official repositories. You can resolve these conflicts by disabling or purging PPAs.

Understanding the Impact of Disabling PPAs:

Disabling a PPA prevents packages installed from that PPA from receiving further updates. The packages themselves will remain on your system, but they won’t be updated, which can sometimes lead to compatibility issues down the line.

Accessing PPA Management:

To manage your PPAs, open the Software & Updates utility:

Press Alt + F2 simultaneously to open the “Run Command” dialog.

Type software-properties-gtk and press Enter. This will launch the Software & Updates utility.

From within this utility, you can disable or purge PPAs, which are discussed in the following sections.

Click on the Other Software tab :

You’ll see a list of PPAs, each represented by two lines:

  • One line for the source code repository.
  • One line for the compiled package repository (often ending in -updates).

To disable a PPA, uncheck the boxes next to both lines associated with that PPA. Make sure to uncheck both the source and the compiled package lines to completely disable the PPA.

Read: How to remove PPA in Ubuntu

You can also purge a PPA. Purging not only disables the PPA but also downgrades any packages installed from that PPA back to the versions available in the official Ubuntu repositories. This is a more thorough way to resolve dependency conflicts caused by PPAs.

Installing PPA-Purge:

To purge a PPA, you first need to install the ppa-purge utility. Open your terminal and run:

sudo apt-get install ppa-purge

Manually Purging a PPA When APT is Broken

If your APT package manager is broken, the standard ppa-purge installation and usage might fail. Here’s a workaround to manually download, install, and use ppa-purge:

Manual Installation of ppa-purge:

Create a temporary directory and download the necessary .deb files:
mkdir ppa-purge && cd ppa-purge && wget http://mirror.pnl.gov/ubuntu/pool/universe/p/ppa-purge/ppa-purge_0.2.8+bzr56_all.deb && wget http://mirror.pnl.gov/ubuntu//pool/main/a/aptitude/aptitude_0.6.6-1ubuntu1_i386.deb

(Note: The specific URLs might need to be adjusted based on your Ubuntu version and architecture. Consider using a mirror closer to your location for faster downloads.)

Install the downloaded packages:
sudo dpkg -i . var wpcf7 = {"apiSettings":{"root":"https:\/\/net2.com\/wp-json\/contact-form-7\/v1","namespace":"contact-form-7\/v1"},"cached":"1"};