5

After Upgrading to Ubuntu 18.04 from 16.04 build-essential, g++, gcc & cpp E: Unable to correct problems, you have held broken packages.

$ sudo apt-get install build-essential
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 build-essential : Depends: gcc (>= 4:7.2) but it is not going to be installed
                   Depends: g++ (>= 4:7.2) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.


$ sudo apt-get install gcc
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 gcc : Depends: gcc-7 (>= 7.3.0-12~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

The same type of output for g++ & cpp

How to fix this?

Melebius
  • 11,431
  • 9
  • 52
  • 78

3 Answers3

2

I've encountered the same - on Ubuntu 16.04 I had the Toolchain Test Builds PPA for gcc and clang builds, including gcc-7. During the upgrade to 18.04, 3rd party repositories were disabled by the installation process, with this PPA included.

To fix this, try (re?)adding the toolchain PPA to your apt sources list:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update

Then, when installing build-essential, it should successfully pick gcc-7 from the toolchain PPA.

valiano
  • 1,985
2

I had the same issue, but apparently I had used a different PPA when I installed those tools.

For me I fixed it with:

sudo add-apt-repository ppa:jonathonf/gcc
Duncan Jones
  • 145
  • 9
0

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:                        
  1. 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:                                                                     
  1.  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
Trect
  • 334