无法在 ubuntu 20.04 中安装 g++

Unable to install g++ in ubuntu 20.04

提问人: 提问时间:5/31/2022 更新时间:5/31/2022 访问量:3820

问:

在这个网站上看到了一些类似的问题。
但是他们都没有得到答复,我无法在那里发表评论,因为我的声望点数较少。

当我运行时,我收到以下错误:sudo apt install g++

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.

当我运行时,我收到以下错误: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: 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.

我需要在 ubuntu20.04 中安装 g++。

感谢您的帮助!

C++ 的Ubuntu ++ Ubuntu-20.04 G++4.9

评论

1赞 Alan Birtles 5/31/2022
试着先做一个。您可能会在 askubuntu.com 上得到更好的回应。例如 askubuntu.com/questions/933253/...apt update
0赞 5/31/2022
@AlanBirtles感谢您的评论!我已经试过了,我也会在askubuntu上问这个问题。apt updateAll packages are up to date.
0赞 Taekahn 5/31/2022
您是否尝试过只安装 gcc 而不是 g++?看起来您的依赖项解析搞砸了。它应该自动安装所需的软件包,但该功能可以关闭或阻止。这是全新安装还是升级?通常最好进行全新安装。
0赞 5/31/2022
@Taekahn感谢您的评论!我可以使用命令安装它。Ubuntu 20.04 已经是全新安装。aptitude
0赞 273K 5/31/2022
尝试 - 它将安装 g++ 或显示它无法安装 gcc 的详细信息sudo apt install g++ gcc

答:

2赞 user17098578 5/31/2022 #1

我通过先安装找到了解决方法。
我按照以下步骤操作:
aptitude

sudo apt-get install aptitude
然后 aptitude 给出一个软件包列表(没有一个安装),
并要求将这些软件包保留在同一版本中。选择“否”()。
然后 aptitude 要求降级一些软件包。选择“是”()。
nY

最后运行命令:sudo aptitude install build-essential

运行上述命令后已经安装,我不需要单独安装它。g++