Score:0

Errors and issues when install G++ on Ubuntu

in flag

Trying to install g++ when I run into this error:

$ sudo apt-get install g++
[sudo] password for eisha: 
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:
 g++ : Depends: g++-9 (>= 9.3.0-3~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

Here is the output of the command $ apt policy g++:

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

Here is the output of the command $ apt policy g++-9:

$ apt policy g++-9
g++-9:
  Installed: (none)
  Candidate: 9.3.0-17ubuntu1~20.04
  Version table:
     9.3.0-17ubuntu1~20.04 500
        500 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages
     9.3.0-10ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages

yes i did try : sudo apt install build-essential and the output is lke this :

sudo apt install build-essential
[sudo] password for eisha: 
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.

And yes i also tried sudo apt update i got a very long output, and the ending lines were:

Last modification reported: Wed, 26 Jan 2022 19:25:00 +0000
   Release file created at: Wed, 26 Jan 2022 16:17:36 +0000
W: Failed to fetch http://us.archive.ubuntu.com/ubuntu/dists/focal-updates/restricted/i18n/Translation-en.xz  
E: Failed to fetch http://us.archive.ubuntu.com/ubuntu/dists/focal-updates/universe/binary-amd64/Packages.xz  
W: Some index files failed to download. They have been ignored, or old ones used instead
ru flag
Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackexchange.com/rooms/133548/discussion-on-question-by-eisha-latif-i-was-installing-g-in-ubuntu-but-unfor).
Score:2
my flag

TL;DR: Downgrade libc6 to libc6=2.31-0ubuntu9.2 and install build-essential.

You don't have the required repositories enabled. Moreover, there are broken versions of the packages.

By running apt-cache policy g++ on Ubuntu 20.04, I get:

g++:
  Installed: (none)
  Candidate: 4:9.3.0-1ubuntu2
  Version table:
     4:9.3.0-1ubuntu2 500
        500 http://mirrors.my mirror.com/ubuntu focal/main amd64 Packages

So, you've to enable the main repository.
Run:

sudo add-apt-repository main && sudo apt update

After enabling the main repository. Install the correct version of libc6:

sudo apt install --reinstall libc6=2.31-0ubuntu9.2

DON'T run apt upgrade.

Now, update and do clean:

sudo apt update
sudo apt clean
sudo apt autoremove
sudo apt -f install

Now, install the meta-package, build-essential to install g++:

sudo apt install aptitude
sudo aptitude -f install build-essential

If the above didn't work, then try restoring the default repositories and using aptitude to install build-essential:

sudo mkdir ~/answer && cd ~/answer/ && sudo wget https://gist.githubusercontent.com/ishad0w/788555191c7037e249a439542c53e170/raw/3822ba49241e6fd851ca1c1cbcc4d7e87382f484/sources.list && sudo sed -i "s/focal/$(lsb_release -c -s)/" ~/answer/sources.list && sudo mv ~/answer/sources.list /etc/apt/ && sudo apt update && sudo apt upgrade  && sudo rm -rf ~/answer
sudo aptitude -f install build-essential

Still didn't work?

Edit your question to include:

  • sudo apt install libc6-dev
  • sudo apt update
  • apt-cache policy libc6
  • apt-cache policy libc-dev

Ping me after adding these details ;)

Artur Meinild avatar
vn flag
Oh is it because of the incorrect `libc6` version?
Someone avatar
my flag
@ArturMeinild Yes.
us flag
Maybe restoring the default repositories (we already have some questions for that) and then fully updating the system would fix the issue?
Someone avatar
my flag
@ArchismanPanigrahi I'm not sure about that (I've already mentioned it in my answer though). But the main problem is the incorrect version of libc.
Score:0
cn flag

As per this documentation try the following:

First, update the package index, sudo apt update.

The recommended way to install the C++ compiler on Ubuntu 20.04 is by installation of the entire development package build-essential.

To install run the following:

$ sudo apt install build-essential

Then to check if it was successfully installed run:

$ g++ --version

You should get an output similar to below:

$ g++ --version
gcc (Ubuntu 9.2.1-17ubuntu1) 9.2.1 20191102
Someone avatar
my flag
Completely wrong answer. If OP can't install `g++` then how will they install `build-essential`? Its obvious, `build-essential` depends on `g++` and installing `g++` is throwing errors!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.