I was facing the same issue while upgrading from 14.04 LTS
to 16.04 LTS
. I have written the detailed solution here. But for the sake of convenience I will reproduce the key points here.
Remove all dependent libraries (autoremove
) and install all missing libraries using sudo apt-get -f install
(-f
means --fix-missing
)
sudo apt-get autoremove
sudo apt-get -f install
sudo apt-get update
sudo apt-get upgrade
Install ubuntu toolchain
from PPA
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
Install aptitude
.
sudo apt install aptitude
Recursively try installing the broken libraries until you solve the conflict by upgrading or fixing a specific library. In my case I had to fix libstdc++6
$ sudo aptitude -f install build-essential
The following NEW packages will be installed:
build-essential cpp{a} cpp-5{a} g++{a} g++-5{a} gcc{a} gcc-5{a} libasan2{a} libcc1-0{ab}
libcilkrts5{a} libgcc-5-dev{a} liblsan0{ab} libmpx0{a} libstdc++-5-dev{a}
The following packages will be upgraded:
gcc-5-base libstdc++6{b}
2 packages upgraded, 14 newly installed, 0 to remove and 5 not upgraded.
Need to get 29.6 MB of archives. After unpacking 100 MB will be used.
The following packages have unmet dependencies:
liblsan0 : Depends: gcc-9-base (= 9.3.0-10ubuntu2~16.04) but 9.3.0-11ubuntu0~14.04 is installed.
libcc1-0 : Depends: gcc-9-base (= 9.3.0-10ubuntu2~16.04) but 9.3.0-11ubuntu0~14.04 is installed.
libstdc++6 : Depends: gcc-9-base (= 9.3.0-10ubuntu2~16.04) but 9.3.0-11ubuntu0~14.04 is installed.
As build-essential
needs gcc-5
.
$ sudo apt-get -f install gcc-5
The following packages have unmet dependencies:
gcc-5 : Depends: cpp-5 (= 5.5.0-12ubuntu1~16.04) but it is not going to be installed
Depends: gcc-5-base (= 5.5.0-12ubuntu1~16.04) but 5.4.0-6ubuntu1~16.04.12 is to be installed
Depends: libcc1-0 (>= 5.5.0-12ubuntu1~16.04) but it is not going to be installed
Depends: libgcc-5-dev (= 5.5.0-12ubuntu1~16.04) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
But gcc-5
in turn depends on cpp-5
$ sudo apt-get -f install cpp-5
The following packages have unmet dependencies:
cpp-5 : Depends: gcc-5-base (= 5.5.0-12ubuntu1~16.04) but 5.4.0-6ubuntu1~16.04.12 is to be installed
cpp-5
depends on gcc-5-base
. Here you can see there is a specific conflict. Aptitide gives multiple choices to solve the conflict. In my case upgrading the libstdc++6
solvd the problem.
$sudo aptitude -f install gcc-5-base
The following packages will be REMOVED:
gcc-5-base{u}
0 packages upgraded, 0 newly installed, 1 to remove and 6 not upgraded.
Need to get 0 B of archives. After unpacking 67.6 kB will be freed.
The following packages have unmet dependencies:
libstdc++6 : Depends: gcc-5-base (= 5.4.0-6ubuntu1~16.04.12) but it is not going to be installed.
open: 115; closed: 488; defer: 35; conflict: 58 .The following actions will resolve these dependencies:
Keep the following packages at their current version:
gcc-5-base [5.4.0-6ubuntu1~16.04.12 (now, xenial-security, xenial-updates)]
Accept this solution? [Y/n/q/?] n
The following actions will resolve these dependencies:
Upgrade the following packages:
libstdc++6 [5.4.0-6ubuntu1~16.04.12 (now, xenial-security, xenial-updates) -> 9.3.0-10ubuntu2~16.0
Finally, now the conlict is resolved try installing build-essentials
again.
$ sudo aptitude -f install build-essential