无法在 ubuntu 20.04 中安装 g++ 和 build-essentials

Posted

技术标签:

【中文标题】无法在 ubuntu 20.04 中安装 g++ 和 build-essentials【英文标题】:unable to install g++ and build-essentials in ubuntu 20.04 【发布时间】:2021-06-26 09:09:17 【问题描述】:

即使在使用apt-get clean 进行清洁后,它仍显示有破损的包裹。 [1] 中提到的 sudo dpkg -l | grep ^..r 不返回任何内容。

$ 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/

【问题讨论】:

你是如何解决这个问题的? 【参考方案1】:

TL;DR:必须降级 libc6 然后才能安装 build-essential

经历过同样的事情:

$ 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.

这是我为修复它所做的。

查看apt-cache policy g++,我认为这已经很满意所以我继续前进:

$ 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

查看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

尝试安装特定版本(如上所示的最新版本):

$ 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.

做了同样的事情,尝试安装特定的libc6 版本:

$ 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
...

强调我收到的警告:dpkg: warning: downgrading libc6:amd64 from 2.31-0ubuntu9.3 to 2.31-0ubuntu9.2

现在我可以安装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]

我阅读了多个不同的 *** 帖子,这些帖子让我使用了我不熟悉的 apt-cache policy $package。然后我就随便玩了。

【讨论】:

我已将我的软件包降级到 9.2 版本,但仍然遇到此问题。这是一个已知问题,我还没有找到解决方法。【参考方案2】:

在寻找答案后,我想手动安装“正确”版本,并在下载 pkg 文件时遇到这个问题:

将以下行添加到 /etc/apt/sources.list:

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

更新包索引:

sudo apt-get update

添加此存储库后,我可以使用以下命令安装 build-essential:

sudo apt-get install build-essential

【讨论】:

这里的问题与 OP 完全相同。你的命令没有解决问题。你能解释一下你的解决方案吗? 添加归档存储库可以提供更多版本,然后 apt-get 可以满足所需的依赖关系。 用这个方法还是没有解决这个问题。【参考方案3】:

我想我偶然发现了一个超级简单的解决方案。没有降级或内核构建。刚刚跑了

sudo apt update && sudo apt upgrade -y

在我的案例中,有 3 个存储库返回错误。比如,

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

刚刚启动了软件更新程序,删除了错误的 PPA,现在我可以安装新软件而无需获取

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

错误。

【讨论】:

【参考方案4】:

您必须从软件和更新申请“规范合作伙伴”的支持。

Software & Updates of Ubuntu20

在 Canonical Partners(不是源代码之一)中标记“打勾”,然后执行

sudo apt install build-essential

【讨论】:

不要忘记在运行 sudo 命令之前关闭窗口来应用软件和更新部分中的更改。

以上是关于无法在 ubuntu 20.04 中安装 g++ 和 build-essentials的主要内容,如果未能解决你的问题,请参考以下文章

无法在 linux ubuntu 20.04 中安装 libgraph

在Ubuntu20.04中安装中文输入法

在Ubuntu20.04中安装中文输入法

在 python 3.8 Ubuntu 20.04 LTS 中安装 RDKit 的问题

在Ubuntu20.04中安装中文输入法

详细介绍如何在ubuntu20.04中安装ROS系统,超快完成安装(最新版教程)