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