无法在 Ubuntu 20.04 中安装 G++ 和 build-essentials



即使用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/

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]

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

在寻找答案后,我想手动手动安装"正确"版本,并在下载 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

我在使用sudo apt install build-essentialUbuntu 22.04 LTS遇到了类似的问题,

错误:

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

解决方案:我尝试使用命令降级包

sudo apt install libc6=2.35-0ubuntu3

但是,它没有解决问题,并导致了最后一个错误:

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

解决方案:所以,我再次降级了错误包

sudo apt-get install libtirpc3=1.3.2-2build1

现在,问题终于消失了,我可以使用

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.

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

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

错误。

运行sudo apt --fix-broken install

然后你可以

sudo apt install build-essential

您必须向 Software & Update 申请"Canonical Partners"的支持。

Ubuntu20 的软件和更新

在Canonical Partners(不是源代码合作伙伴)中标记"勾号",然后执行

sudo apt install build-essential

相关内容

  • 没有找到相关文章

最新更新