unable to install g++ and build-essentials in ubuntu 20.04
Asked Answered
S

6

13

even after cleaning with apt-get clean it says there are broken packages. sudo dpkg -l | grep ^..r as mentioned in [1] returns nothing.

$ 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: libc6-dev but it is not going to be installed or
                            libc-dev
                   Depends: g++ (>= 4:9.2) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

[1] https://www.techbrown.com/fix-broken-packages-ubuntu-debian/

Sustain answered 30/3, 2021 at 10:41 Comment(1)
How did you solve the issue?Blasphemy
O
19

TL;DR: had to downgrade libc6 and then was able to install build-essential

Experienced the same thing:

$ sudo apt 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: libc6-dev but it is not going to be installed or
                            libc-dev
                   Depends: g++ (>= 4:9.2) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

Here's what I did to fix it.

Checked apt-cache policy g++, I thought this was already satisfied so I moved on:

$ apt-cache policy g++
g++:
  Installed: (none)
  Candidate: 4:9.3.0-1ubuntu2
  Version table:
     4:9.3.0-1ubuntu2 500
        500 http://mirrors.xtom.com/ubuntu focal/main amd64 Packages

Checked apt-cache policy libc6-dev:

$ apt-cache policy libc6-dev
libc6-dev:
  Installed: (none)
  Candidate: 2.31-0ubuntu9.2
  Version table:
     2.31-0ubuntu9.2 500
        500 http://mirrors.xtom.com/ubuntu focal-updates/main amd64 Packages
     2.31-0ubuntu9 500
        500 http://mirrors.xtom.com/ubuntu focal/main amd64 Packages

Tried to install a specific version (the latest shown above):

$ sudo apt install libc6-dev=2.31-0ubuntu9.2
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:
 libc6-dev : Depends: libc6 (= 2.31-0ubuntu9.2) but 2.31-0ubuntu9.3 is to be installed
E: Unable to correct problems, you have held broken packages.

Did the same thing, tried to install that specific libc6 version:

$ sudo apt install libc6=2.31-0ubuntu9.2
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
  glibc-doc
The following packages will be DOWNGRADED:
  libc6
0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.
Need to get 2,715 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n]
...
dpkg: warning: downgrading libc6:amd64 from 2.31-0ubuntu9.3 to 2.31-0ubuntu9.2
...

Emphasis on the warning I got: dpkg: warning: downgrading libc6:amd64 from 2.31-0ubuntu9.3 to 2.31-0ubuntu9.2

Now I was able to install build-essential:

$ sudo apt install build-essential
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  g++ g++-9 libc-dev-bin libc6-dev libcrypt-dev libstdc++-9-dev linux-libc-dev manpages-dev
Suggested packages:
  g++-multilib g++-9-multilib gcc-9-doc glibc-doc libstdc++-9-doc
The following NEW packages will be installed:
  build-essential g++ g++-9 libc-dev-bin libc6-dev libcrypt-dev libstdc++-9-dev linux-libc-dev manpages-dev
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 16.2 MB of archives.
After this operation, 77.1 MB of additional disk space will be used.
Do you want to continue? [Y/n]

I read multiple different stackoverflow posts that led me to use the apt-cache policy $package that I was not familiar with. Then I just played around.

Onomasiology answered 19/5, 2021 at 5:28 Comment(2)
I've downgraded my packages to the 9.2 version and still get this issue. It is a known issue and I haven't found a workaround yet.Implode
For me the only solutions was this: askubuntu.com/a/1340808/920914Wadai
W
6

After looking for an answer, I figured to manually install the "correct" version manually, and came across this when downloading the pkg file:

Add the following line to /etc/apt/sources.list:

deb http://archive.ubuntu.com/ubuntu/ focal-proposed main

Update the package index:

sudo apt-get update

After adding this repository, I was able to install build-essential with the command:

sudo apt-get install build-essential
Wrongdoing answered 28/4, 2021 at 21:17 Comment(4)
Exactly the same problem as the OP here. Your command didn't solve the problem. Can you explain your solution?Blasphemy
Adding the archive repository makes several more versions available, and apt-get can then satisfy the required dependencies.Wrongdoing
This problem still isn't resolved using this method.Implode
what is deb command?Tedmund
T
3

I had a similar problem in Ubuntu 22.04 LTS While I was using sudo apt install build-essential,

error:

...
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:
 libc6-dev : Depends: libc6 (= 2.35-0ubuntu3) but 2.35-0ubuntu3.1 is to be installed
             Depends: libtirpc-dev but it is not going to be installed
             Depends: libnsl-dev but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

solution: I tried to down-grade the package with command

sudo apt install libc6=2.35-0ubuntu3

However, it did not solve the problem, and lead to the last error:

...
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:
 libtirpc-dev : Depends: libtirpc3 (= 1.3.2-2build1) but 1.3.2-2ubuntu0.1 is to be installed
E: Unable to correct problems, you have held broken packages.

Solution: So, I again downgraded the error package

sudo apt-get install libtirpc3=1.3.2-2build1

Now, finally the problem gone and I can use

sudo apt-get install build-essential

g++ --version
g++ (Ubuntu 11.2.0-19ubuntu1) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Tedmund answered 27/10, 2022 at 15:30 Comment(0)
L
1

I suppose I found a super simple solution by chance. No downgrade or kernel builds. Just ran

sudo apt update && sudo apt upgrade -y

There were 3 repositories returning errors in my case. Such as,

E: The repository 'cdrom://Ubuntu 20.04 LTS _Focal Fossa_ - Release amd64 (20200423) focal Release' does not have a Release file.

Just launched software updater, removed PPAs with errors, now I'm able to install new software without getting

Depends: libc6 (>= 2.33) but 2.31-0ubuntu9.2 is to be installed

error.

Leotaleotard answered 7/9, 2021 at 9:52 Comment(0)
A
0

run sudo apt --fix-broken install

then you can

sudo apt install build-essential

Almallah answered 24/8, 2023 at 2:50 Comment(0)
S
-2

You have to apply for support of 'Canonical Partners' from Software & Updates.

Software & Updates of Ubuntu20

Mark 'tick' in Canonical Partners (not the source code one) and then do

sudo apt install build-essential
Sorensen answered 2/12, 2021 at 9:39 Comment(1)
Don't forget to apply changes in the Software & Updates section by closing the window before running sudo command.Sorensen

© 2022 - 2024 — McMap. All rights reserved.