apt --fix-broken install not working

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.


Solution 1:

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.