$ sudo apt install build-essential
Reading package lists... Done
Building dependency tree... Done
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: cpp (= 4:9.3.0-1ubuntu2) but 4:11.2.0-1ubuntu1 is to be installed
gcc : Depends: cpp (= 4:9.3.0-1ubuntu2) but 4:11.2.0-1ubuntu1 is to be installed
libc6-dev : Depends: libc6 (= 2.31-0ubuntu9.9) but 2.35-0ubuntu3.1 is to be installed
Depends: libc-dev-bin (= 2.31-0ubuntu9.9)
Depends: libcrypt-dev but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
答案1
根据请求,您提供的输出apt policy build-essential
如下:
Installed: (none)
Candidate: 12.8ubuntu1.1
Version table:
12.8ubuntu1.1 500 500 archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
12.8ubuntu1 500 500 archive.ubuntu.com/ubuntu focal/main amd64 Packages
这里明显的问题是您正在运行 22.04 (jammy) 并且正在使用 20.04 (focal) 源。
该包在 22.04 中的正确输出如下所示
Installed: 12.9ubuntu3
Candidate: 12.9ubuntu3
Version table:
*** 12.9ubuntu3 500
500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
100 /var/lib/dpkg/status
解决方法是纠正/etc/apt/sources.list