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

12

即使使用apt-get clean清理后,它仍然显示有损坏的软件包。sudo dpkg -l | grep ^..r如[1]所述没有返回内容。

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


你是如何解决这个问题的? - Silicomancer
6个回答

19

简述:不得不降级 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 命令。然后我只是做了一些尝试。


1
我已将软件包降级至9.2版本,但仍然遇到此问题。这是一个已知问题,我尚未找到解决方法。 - rlillbac
对我来说,唯一的解决方案是这个:https://askubuntu.com/a/1340808/920914 - Francesco Taioli

6
在寻找答案后,我决定手动安装“正确”的版本,并在下载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

2
这里和原帖有完全相同的问题。你的命令没有解决问题。你能解释一下你的解决方案吗? - Silicomancer
添加归档存储库会使更多版本可用,然后apt-get便能满足所需的依赖项。 - Jorge Valdes
这个问题仍然无法通过这种方法解决。 - rlillbac
什么是 deb 命令? - bim

3

我在使用 sudo apt install build-essential 的过程中,在 Ubuntu 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.

1

我偶然发现了一个超级简单的解决方案,无需降级或内核构建,只需要运行

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

错误。

0
运行 sudo apt --fix-broken install 然后你可以
运行 sudo apt install build-essential

-2

您需要从“软件和更新”中申请“Canonical合作伙伴”的支持。

Ubuntu20的软件和更新

在“Canonical合作伙伴”(不是源代码)旁边打上“勾”,然后执行操作。

sudo apt install build-essential

不要忘记在运行sudo命令之前关闭窗口并在"软件和更新"部分应用更改。 - rafat.tushar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接