2

I am using Ubuntu 20.04. When I execute the command:

sudo apt-get install build-essential

I get the output:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
build-essential is already the newest version (12.8ubuntu1.1).
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 fontconfig:i386 : Depends: libfreetype6:i386 (>= 2.8.1) but 2.6.1-0.1ubuntu2 is to be installed
 libcairo2:i386 : Depends: libfreetype6:i386 (>= 2.9.1) but 2.6.1-0.1ubuntu2 is to be installed
 libfontconfig1:i386 : Depends: libfreetype6:i386 (>= 2.9.1) but 2.6.1-0.1ubuntu2 is to be installed
 libfreetype6 : Breaks: libfreetype6:i386 (!= 2.10.1-2ubuntu0.1) but 2.6.1-0.1ubuntu2 is to be installed
 libfreetype6:i386 : Depends: libpng12-0:i386 (>= 1.2.13-4) but it is not installable
                     Breaks: libfreetype6 (!= 2.6.1-0.1ubuntu2) but 2.10.1-2ubuntu0.1 is to be installed
 libharfbuzz0b:i386 : Depends: libfreetype6:i386 (>= 2.9.1) but 2.6.1-0.1ubuntu2 is to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

When I check

sudo apt --fix-broken install

I get the output

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... failed.
The following packages have unmet dependencies:
 fontconfig:i386 : Depends: libfreetype6:i386 (>= 2.8.1) but 2.6.1-0.1ubuntu2 is installed
 libcairo2:i386 : Depends: libfreetype6:i386 (>= 2.9.1) but 2.6.1-0.1ubuntu2 is installed
 libfontconfig1:i386 : Depends: libfreetype6:i386 (>= 2.9.1) but 2.6.1-0.1ubuntu2 is installed
 libfreetype6 : Breaks: libfreetype6:i386 (!= 2.10.1-2ubuntu0.1) but 2.6.1-0.1ubuntu2 is installed
 libfreetype6:i386 : Depends: libpng12-0:i386 (>= 1.2.13-4) but it is not installable
                     Breaks: libfreetype6 (!= 2.6.1-0.1ubuntu2) but 2.10.1-2ubuntu0.1 is installed
 libharfbuzz0b:i386 : Depends: libfreetype6:i386 (>= 2.9.1) but 2.6.1-0.1ubuntu2 is installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.
E: Unable to correct dependencies

I was trying to set up Modelsim on Ubuntu 20.04 with those libfree packages but it seems that I have ruined everything. Is there anyway I can completely get rid of them? I tried removing them and the output of the command

sudo dpkg --configure -a

is empty now but I'm still receiving the errors above.

2 Answers2

6

I found some resources on the web, which might be useful.

Solution 1

As HVNSweeting says in their answer, they fixed it by following the below:

First, run:

dpkg -l | grep ^iU | awk '{print $2}' | xargs sudo dpkg --purge

If the output is:

dpkg: error: --purge needs at least one package name argument

Type dpkg --help for help about installing and deinstalling packages [*]; Use 'apt' or 'aptitude' for user-friendly package management; Type dpkg -Dhelp for a list of dpkg debug flag values; Type dpkg --force-help for a list of forcing options; Type dpkg-deb --help for help about manipulating *.deb files;

Options marked [*] produce a lot of output - pipe it through 'less' or 'more' !

Then go to the next solution, or run:

sudo apt update && sudo apt upgrade

Done!


Solution 2

As Amlan Saha Kundu says in their answer on Super User, you need to clear the contents of /var/lib/dpkg/status.

To do the above:

  1. Backup the file by running:

    sudo cp -r /var/lib/dpkg/status $HOME
    
  2. Then clear the contents by running:

    echo > /var/lib/dpkg/status
    
  3. After that run:

    sudo apt update && sudo apt upgrade
    

You can search the issue to get more solutions.

Error404
  • 7,440
  • This also worked for me on Ubuntu 23: Suddenly the nvidia driver had stopped working after a reboot, and I couldn't just delete it and install a new one because of broken dependencies. Thank you for sharing this! – alexpanter Jul 07 '23 at 10:53
3

Looks like you tried to install 20.04 (focal) packages on a 16.04 (xenial) system.

As you have learned to your sorrow, mixing packages from different releases of Ubuntu is likely to break your system. If you need newer packages, you must run a newer release of Ubuntu.

Since you have a horrifying mixture of both packages on your system (we call that a Frankensystem), the simplest option is to back up your data and then reinstall Ubuntu.

It's quite possible for somebody with skills and patience to carefully read each error message and downgrade each focal package back to xenial. There is (obviously) no single, simple command for that. Once your data is backed up, feel free to give it a try -- if it becomes impossible then reinstall.

user535733
  • 62,253
  • My Ubuntu version is 20.04. So I think I tried to install xenial packages on a focal system. Right? Can't this be fixed with an upgrade on the packages? – Daneshvar Amrollahi Apr 08 '21 at 22:17
  • 1
    Of course it can...if you are both patient and skilled. It's the same process, solving each error in order. You must figure out what the problem is and why it's a problem. For example, looks like you have the 16.04 version of libfreetype6. You must figure out what you installed that requires the Xenial version, and cannot be upgraded. Then you must uninstall that wrong-version package, which will allow libfreetype6 to upgrade to focal, which will eliminate that particular set of errors. – user535733 Apr 08 '21 at 22:39
  • I should find the package which is dependant on libfreetype6. Right? And then reinstall that? – Daneshvar Amrollahi Apr 09 '21 at 09:27
  • 1
    It it were a simple reinstall, apt likely would have taken care of it already. You might need to uninstall the package that is blocking upgrades. – user535733 Apr 09 '21 at 12:55