Can not install gcc

Unable to install gcc (Ubuntu 18.04 mate)

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.

I have tried a lot of apt commands without any solution, tried those:

dpkg --get-selections | grep hold
apt update ; apt autoremove

with aptitude I get some more information.

$ aptitude install gcc
The following NEW packages will be installed:
  gcc gcc-7{ab} libasan4{ab} libatomic1{ab} libc-dev-bin{a} libc6-dev{a} libcilkrts5{ab} libgcc-7-dev{ab} libitm1{ab} liblsan0{ab} libmpx2{ab} 
  libquadmath0{ab} libtsan0{ab} libubsan0{ab} linux-libc-dev{a} manpages-dev{a} 
0 packages upgraded, 16 newly installed, 0 to remove and 0 not upgraded.
Need to get 16,8 MB of archives. After unpacking 73,2 MB will be used.
The following packages have unmet dependencies:
 libgcc-7-dev : Depends: gcc-7-base (= 7.3.0-16ubuntu3) but 7.3.0-27ubuntu1~18.04 is installed
 libmpx2 : Depends: gcc-8-base (= 8-20180414-1ubuntu2) but 8.2.0-1ubuntu2~18.04 is installed
 libitm1 : Depends: gcc-8-base (= 8-20180414-1ubuntu2) but 8.2.0-1ubuntu2~18.04 is installed
 libcilkrts5 : Depends: gcc-7-base (= 7.3.0-16ubuntu3) but 7.3.0-27ubuntu1~18.04 is installed
 libasan4 : Depends: gcc-7-base (= 7.3.0-16ubuntu3) but 7.3.0-27ubuntu1~18.04 is installed
 libquadmath0 : Depends: gcc-8-base (= 8-20180414-1ubuntu2) but 8.2.0-1ubuntu2~18.04 is installed
 libtsan0 : Depends: gcc-8-base (= 8-20180414-1ubuntu2) but 8.2.0-1ubuntu2~18.04 is installed
 libubsan0 : Depends: gcc-7-base (= 7.3.0-16ubuntu3) but 7.3.0-27ubuntu1~18.04 is installed
 gcc-7 : Depends: cpp-7 (= 7.3.0-16ubuntu3) but 7.3.0-27ubuntu1~18.04 is installed
         Depends: gcc-7-base (= 7.3.0-16ubuntu3) but 7.3.0-27ubuntu1~18.04 is installed
 liblsan0 : Depends: gcc-8-base (= 8-20180414-1ubuntu2) but 8.2.0-1ubuntu2~18.04 is installed
 libatomic1 : Depends: gcc-8-base (= 8-20180414-1ubuntu2) but 8.2.0-1ubuntu2~18.04 is installed
The following actions will resolve these dependencies:

      Keep the following packages at their current version:
1)      gcc [Not Installed]                                
2)      gcc-7 [Not Installed]                              
3)      libasan4 [Not Installed]                           
4)      libatomic1 [Not Installed]                         
5)      libcilkrts5 [Not Installed]                        
6)      libgcc-7-dev [Not Installed]                       
7)      libitm1 [Not Installed]                            
8)      liblsan0 [Not Installed]                           
9)      libmpx2 [Not Installed]                            
10)     libquadmath0 [Not Installed]                       
11)     libtsan0 [Not Installed]                           
12)     libubsan0 [Not Installed]

I'm presuming from the last of the output, some packages are held. Did this command output anything?

dpkg --get-selections | grep hold

If there is, unmark them as held - you could use Synaptic for this.


It is a classic scenario of broken packages due to a dependency problem. Try running these commands:

To install missing packages:

sudo apt-get update --fix-missing

To gracefully finish installing any packages that might not be fully installed:

sudo dpkg –configure -a

To attempt to fix the broken packages:

sudo apt-get install -f

:point_up: Similar commands are ran in :ubuntu_mate: Software Boutique's "Fixes" section.


Otherwise, if those commands do not improve the problem, try removing the packages causing the conflict and install gcc again:

sudo apt purge gcc
sudo apt autoremove     # This should remove any installed gcc dependencies
sudo apt install gcc
2 Likes

Ubuntu way of installing gcc is:

sudo apt install build-essential

Cheers!

1 Like

THank you all!.
After trying everything the way I fixed was:

  1. delete all repository sources
    rm -rfv /etc/apt/sources.list.d/*
    mv /etc/apt/sources.list /etc/apt/sources.list.BKP
  2. then I just added these
    deb http://it.archive.ubuntu.com/ubuntu/ bionic main universe restricted multiverse
    deb-src http://it.archive.ubuntu.com/ubuntu/ bionic main universe restricted multiverse

apt update

now i can install whatever, no more broken packages errors.

i hope it helps out someone out there, it took me 2 days to fix mine.

cheers,
Felipe