Authors Top

If you have a few years of experience in the Linux ecosystem, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines.

1. Overview

When installing or upgrading particular packages in our system using the apt-get command, we may often run into the “unmet dependencies” error. In this tutorial, we’ll talk about what this error means and learn how to resolve it.

2. Fixing Unmet Dependencies Error in Ubuntu

Sometimes, when installing a package/program that is no longer supported or from a third-party dependency, we might run into this “unmet dependency” error. This happens because the apt-get command tries to install the package, but the package is looking for dependencies and can’t find available current versions of them. This error will frequently occur depending on what program we’re installing and from which dependencies it comes.

When we’re fixing this error, we should note that it’s crucial to take a backup of some of our configuration files. These files include the /etc/apt/sources.list and /var/lib/dpkg/status. Once we’ve taken the backup, it’ll be easier to make changes if something goes wrong.

3. Using apt-get With the -f Flag

When we run into this error, we can use the -f flag with the apt-get command and try to correct the system, which now has broken dependencies. If successful, we’ll be able to install the package/program without experiencing this error again. Otherwise, it will throw the same error.

Let’s see the -f flag in action:

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

If we get the following output after we’ve run the above commands, it means the error isn’t fixed:

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

4. Using aptitude

Alternatively, apart from the apt-get command, we can also use aptitude. This high-level package manager will fix “unmet dependencies” errors for us. First, let’s install it:

$ sudo apt-get update
$ sudo apt-get install aptitude

After the installation is complete, let’s use aptitude to install the program that gave us the error:

$ sudo aptitude install package-name

5. Removing Held Packages

Sometimes, we may run into packages that can’t be upgraded, removed, or even changed. These are called held packages. Eliminating these kinds of packages can fix the unmet dependencies issue.

Let’s list the held packages on our system:

$ sudo apt-get -u dist-upgrade
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:
  linux-headers-5.15.0-52 linux-headers-5.15.0-52-generic
The following packages will be upgraded:
  fonts-opensymbol libksba8 libperl5.34 libreoffice-base-core libreoffice-calc
[*list of more packages to be upgraded]
40 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
40 standard LTS security updates
After this operation, 584 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
done

If this runs successfully, it upgrades and installs the new packages. Then, the unmet dependency issue we’ll be resolved. Otherwise, it’ll list the held packages as those that are kept back:

$ sudo apt -u dist-upgrade
Reading package lists... Done 
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done 
The following packages were automatically installed and are no longer required:
  libreoffice-impress libreoffice-math libreoffice-ogltrans
Use 'sudo apt autoremove' to remove them.
The following packages have been kept back: 
  libreoffice-help-common libreoffice-help-en-us
  thunderbird-locale-en thunderbird-locale-en-us
0 upgraded, 0 newly installed, to remove and 4 not upgraded.

Now, we’ll debug and upgrade the packages that have been kept back. Let’s run this command, after which it should remove the error:

$ sudo apt-get -o Debug::pkgProblemResolver=yes dist-upgrade
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Starting pkgProblemResolver with broken count: 0
Starting 2 pkgProblemResolver with broken count: 0
Done
Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
  linux-image-5.13.0-19-generic linux-modules-5.13.0-19-generic
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

If we get the above output with nothing upgraded, installed, or removed, the command was successful. All the packages have either been upgraded, removed, or installed, and none is remaining, and the error is resolved. On the other hand, if our output still has something like:

The following packages have been kept back: 
  libreoffice-help-common libreoffice-help-en-us thunderbird- 
  locale-en thunderbird-locale-en-us 
0 upgraded, 0 newly installed, to remove and 4 not upgraded.

Then the error still exists and hasn’t been resolved. And given that we now have the names of the packages causing the error, we’ll have to remove them one by one. Let’s run a mock, and if it’s successful, we proceed and remove the package:

$ sudo apt-get remove --dry-run libreoffice-help-common
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-image-5.13.0-19-generic linux-modules-5.13.0-19-generic
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  libreoffice-help-common libreoffice-help-en-us
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
Remv libreoffice-help-en-us [1:7.3.6-0ubuntu0.22.04.2]
Remv libreoffice-help-common [1:7.3.6-0ubuntu0.22.04.2]
$ sudo apt-get remove libreoffice-help-common

6. Clearing the Package Database

A corrupted system database can also cause the unmet dependencies error. To correct this, let’s clear out our package database:

$ sudo apt-get clean 
$ sudo apt-get autoclean

The first command will clean the local repositories, except the lock files from /var/cache/apt/archives and /var/cache/apt/archives/partial. The second command will remove the outdated packages that can’t be downloaded.

7. Removing PPAs

Personal Package Archives (PPA) are repositories hosted on Launchpad and are used to upgrade or install packages that aren’t usually available in the official Ubuntu repositories. We’ll run into the unmet dependencies error in most instances if we use the PPA repositories to update packages existing on the official Ubuntu repositories.

7.1. Using the Terminal

Let’s list the available repositories in our Ubuntu:

$ sudo apt policy

To know which PPA repository is in our system, we look at the beginning of the lines and try to find the lines that begin with “https://ppa.*”.

Once we’ve determined the name of the PPA repository, let’s remove it:

$ sudo apt-get autoremove –purge package-name
$ sudo add-apt-repository –remove ppa:someppa/ppa
$ sudo apt-get autoclean

After that, we can check again, using the apt policy command, if the PPA repo is still there and should not appear on the list.

7.2. Using the Software Updater

We can also remove PPAs using the Software Updater application from the Ubuntu launcher. First, let’s open it by clicking and selecting the “Software Updater” icon and then clicking the “Settings…” button:

softwareupdater

Clicking “Settings” should open the window under the “Ubuntu Software” tab. On that tab, we should make sure the first two options are checked. The other two are optional, but let’s check them. We should also confirm that the download server is the “Main server”:

 

ubuntusoftware

After this, let’s select the “Other Software” tab. This window should be empty if there are no PPA repositories. Otherwise, if they exist, we’ll need to uncheck the selected PPAs:

 

ppa

Next, we click the “Close” button on the bottom right to save the changes we’ve made, and finally, click “Reload” to install updates.

8. Conclusion

In this article, we’ve looked at the various ways to resolve the “unmet dependency” error. We looked at using the -f flag, the aptitude command, removing held packages and PPAs, and clearing the package database. Lastly, we should keep our system up-to-date, and if we plan to use PPAs, we should ensure they’re from trusted sources.

Authors Bottom

If you have a few years of experience in the Linux ecosystem, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines.

Comments are closed on this article!