0

I have seen some questions similar to this on this website old latest.
But none of them have been answered and I am unable to comment there because I have less reputation points.

When I run sudo apt install g++ I get the following error:

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: gcc (= 4:9.3.0-1ubuntu2) but it is not going to be installed
       Depends: g++-9 (>= 9.3.0-3~) but it is not going to be installed
       Depends: gcc-9 (>= 9.3.0-3~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

When I run sudo apt install build-essential I get the following error:

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

I need to install g++ in ubuntu20.04.

Thanks for the help!

  • 1
    try doing an `apt update` first. You'll probably get better responses on https://askubuntu.com. e.g https://askubuntu.com/questions/933253/but-it-is-not-going-to-be-installed-nightmare – Alan Birtles May 30 '22 at 18:07
  • @AlanBirtles Thanks for the comment! I had tried ```apt update``` it returns ```All packages are up to date.``` I'll also ask the question on askubuntu. –  May 30 '22 at 18:12
  • Have you tried just installing gcc instead of g++? It looks like something is messed up with your dependency resolution. It should automatically install needed packages, but that feature can be turned off or blocked. Is this a fresh install or an upgrade? It’s usually better to do a fresh install. – Taekahn May 30 '22 at 18:37
  • @Taekahn Thanks for the comment! I could install it using ```aptitude``` command. Ubuntu 20.04 is already a fresh install. –  May 30 '22 at 18:51
  • Try `sudo apt install g++ gcc` - it will either install g++ or show details why it can't install gcc – 273K May 30 '22 at 19:17

1 Answers1

2

I found a work around by installing aptitude first.
I followed the following steps:

sudo apt-get install aptitude
Then aptitude gives a list of packages (none of which were installed)
and asks to keep those packages in the same version. Choose No (n).
Then aptitude asks to downgrade some packages. Choose Yes (Y).

Finally run the command: sudo aptitude install build-essential

After running the above command g++ was already install and I didn't need to separately install it.\