Ubuntu安装g++-7 : Depends: libstdc++-7-dev (= 7.5.0-6ubuntu2) but it is not going to be installedE: Un

直接安装g++会出现错误:

The following packages have unmet dependencies:
 g++ : Depends: g++-9 (>= 9.3.0-3~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

我怀疑是ubuntu自动安装的gcc9.4.0的版本无法匹配导致。因此我主动安装gcc-7:

sudo apt-get install gcc-7

是可以安装成功的,但是当我使用sudo apt-get install g++-7却始终无法安装,报错:
The following packages have unmet dependencies:
g+±7 : Depends: libstdc+±7-dev (= 7.5.0-6ubuntu2) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
我就顺着报告的依赖去一个个安装,就有了下面的过程:

zyl@zyl:~$ sudo apt-get install g++
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:
 g++ : Depends: g++-9 (>= 9.3.0-3~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
zyl@zyl:~$ sudo apt-get install g++-7
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:
 g++-7 : Depends: libstdc++-7-dev (= 7.5.0-6ubuntu2) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
zyl@zyl:~$ sudo apt-get install libstdc++-7-dev
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:
 libstdc++-7-dev : Depends: libc6-dev (>= 2.13-0ubuntu6) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
zyl@zyl:~$ sudo apt-get install libc6-dev
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.7) but 2.31-0ubuntu9.9 is to be installed
E: Unable to correct problems, you have held broken packages.
zyl@zyl:~$ sudo apt-get install libc6
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libc6 is already the newest version (2.31-0ubuntu9.9).
libc6 set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

这里,我发现在sudo apt-get install libc6之后报告的却是libc6 is already the newest version。那大概率有别的问题。上面一条报告的发现有不匹配的情况,还提示you have held broken packages.我怀疑是这里的问题

libc6-dev : Depends: libc6 (= 2.31-0ubuntu9.7) but 2.31-0ubuntu9.9 is to be installed
E: Unable to correct problems, you have held broken packages.

我去搜了一下别人的情况,发现也有人出现类似的问题。

参考:https://askubuntu.com/questions/1315906/unmet-dependencies-libc6-the-package-system-is-broken
作者的问题:
I’ve tried apt --fix-broken install
I’ve tried sudo apt-get -f install to force install.
I get the same error messages in both cases.
I’ve tried apt --fix-broken install
I’ve tried sudo apt-get -f install to force install.
I get the same error messages in both cases.

我也尝试着这么去做:

zyl@zyl:~$ sudo apt --fix-broken install libc6
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libc6 is already the newest version (2.31-0ubuntu9.9).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
zyl@zyl:~$ sudo apt --fix-broken install libc6-dev
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.7) but 2.31-0ubuntu9.9 is to be installed
E: Unable to correct problems, you have held broken packages.

发现仍然是这种依赖对应不上的问题。于是我猜测需要重新安装匹配的依赖?而上述问题的回答者也确是如此,
而给出的解决方法是:

I had similar issue on freshly installed Ubuntu 20.04.2 desktop 64bit, the difference is that libc6 …9.3 was installed but my packages (g++ build-essential etc) could not be installed beceause libc6-dev could not be installed because it required libc6 …9.2 which was older then the one installed
libc6-dev : Depends: libc6 (= 2.31-0ubuntu9.2) but 2.31-0ubuntu9.3 is to be installed
So I just downgraded libc6 (and libc-bin too, because it seems very related to me) to version 2.31-0ubuntu9.2 this way:
sudo apt install libc6=2.31-0ubuntu9.2 libc-bin=2.31-0ubuntu9.2
Now my packages could install 😃 so it seems to work, let’s see if we don’t have much problems - but I guess not because this is a tiny change in libc (on the other side libc is very important)
BUT I DON’T KNOW WHAT WILL HAPPEN IN THE FUTURE:
Will it in future updates hold this package fixed to still old version?
Does anyone know how to unfix this version?
Even if I could somehow unfix it from this version, then will ubuntu have this issue in the future?
Does anyone know if it is some bug in Ubuntu packaging repository? I repeat: this was on a totally fresh Ubuntu 20.04 desktop
Some other places to look for inspiration:
https://serverfault.com/a/993629/445123
https://serverfault.com/a/1005063/445123

于是,我参考了它的指令,就有了如下的记录:

zyl@zyl:~$ sudo apt install libc6=2.31-0ubuntu9.7 libc-bin=2.31-0ubuntu9.7
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libc-bin is already the newest version (2.31-0ubuntu9.7).
libc-bin set to manually installed.
Suggested packages:
  glibc-doc
The following packages will be REMOVED:
  libc6-dbg
The following packages will be DOWNGRADED:
  libc6
0 upgraded, 0 newly installed, 1 downgraded, 1 to remove and 0 not upgraded.
Need to get 2,266 kB of archives.
After this operation, 26.9 MB disk space will be freed.
Do you want to continue? [Y/n] y
Get:1 http://ports.ubuntu.com/ubuntu-ports focal-security/main arm64 libc6 arm64 2.31-0ubuntu9.7 [2,266 kB]
Fetched 2,266 kB in 4s (638 kB/s)  
Preconfiguring packages ...
(Reading database ... 152198 files and directories currently installed.)
Removing libc6-dbg:arm64 (2.31-0ubuntu9.9) ...
dpkg: warning: downgrading libc6:arm64 from 2.31-0ubuntu9.9 to 2.31-0ubuntu9.7
(Reading database ... 151722 files and directories currently installed.)
Preparing to unpack .../libc6_2.31-0ubuntu9.7_arm64.deb ...
Unpacking libc6:arm64 (2.31-0ubuntu9.7) over (2.31-0ubuntu9.9) ...
Setting up libc6:arm64 (2.31-0ubuntu9.7) ...
Processing triggers for libc-bin (2.31-0ubuntu9.7) ...
zyl@zyl:~$ sudo apt --fix-broken install libc6-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libc-dev-bin libcrypt-dev linux-libc-dev manpages-dev
Suggested packages:
  glibc-doc
The following NEW packages will be installed:
  libc-dev-bin libc6-dev libcrypt-dev linux-libc-dev manpages-dev
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 5,596 kB of archives.
After this operation, 27.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://ports.ubuntu.com/ubuntu-ports focal-security/main arm64 libc-dev-bin arm64 2.31-0ubuntu9.7 [64.2 kB]
Get:2 http://ports.ubuntu.com/ubuntu-ports focal-security/main arm64 linux-libc-dev arm64 5.4.0-149.166 [1,097 kB]
Get:3 http://ports.ubuntu.com/ubuntu-ports focal/main arm64 libcrypt-dev arm64 1:4.4.10-10ubuntu4 [111 kB]
Get:4 http://ports.ubuntu.com/ubuntu-ports focal-security/main arm64 libc6-dev arm64 2.31-0ubuntu9.7 [2,059 kB]
Get:5 http://ports.ubuntu.com/ubuntu-ports focal/main arm64 manpages-dev all 5.05-1 [2,266 kB]
Fetched 5,596 kB in 5s (1,208 kB/s)     
Selecting previously unselected package libc-dev-bin.
(Reading database ... 151722 files and directories currently installed.)
Preparing to unpack .../libc-dev-bin_2.31-0ubuntu9.7_arm64.deb ...
Unpacking libc-dev-bin (2.31-0ubuntu9.7) ...
Selecting previously unselected package linux-libc-dev:arm64.
Preparing to unpack .../linux-libc-dev_5.4.0-149.166_arm64.deb ...
Unpacking linux-libc-dev:arm64 (5.4.0-149.166) ...
Selecting previously unselected package libcrypt-dev:arm64.
Preparing to unpack .../libcrypt-dev_1%3a4.4.10-10ubuntu4_arm64.deb ...
Unpacking libcrypt-dev:arm64 (1:4.4.10-10ubuntu4) ...
Selecting previously unselected package libc6-dev:arm64.
Preparing to unpack .../libc6-dev_2.31-0ubuntu9.7_arm64.deb ...
Unpacking libc6-dev:arm64 (2.31-0ubuntu9.7) ...
Selecting previously unselected package manpages-dev.
Preparing to unpack .../manpages-dev_5.05-1_all.deb ...
Unpacking manpages-dev (5.05-1) ...
Setting up manpages-dev (5.05-1) ...
Setting up linux-libc-dev:arm64 (5.4.0-149.166) ...
Setting up libcrypt-dev:arm64 (1:4.4.10-10ubuntu4) ...
Setting up libc-dev-bin (2.31-0ubuntu9.7) ...
Setting up libc6-dev:arm64 (2.31-0ubuntu9.7) ...
Processing triggers for man-db (2.9.1-1) ...
zyl@zyl:~$ sudo apt-get install libstdc++-7-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  libstdc++-7-doc
The following NEW packages will be installed:
  libstdc++-7-dev
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,471 kB of archives.
After this operation, 16.0 MB of additional disk space will be used.
Get:1 http://ports.ubuntu.com/ubuntu-ports focal/universe arm64 libstdc++-7-dev arm64 7.5.0-6ubuntu2 [1,471 kB]
Fetched 1,471 kB in 3s (564 kB/s)          
Selecting previously unselected package libstdc++-7-dev:arm64.
(Reading database ... 155374 files and directories currently installed.)
Preparing to unpack .../libstdc++-7-dev_7.5.0-6ubuntu2_arm64.deb ...
Unpacking libstdc++-7-dev:arm64 (7.5.0-6ubuntu2) ...
Setting up libstdc++-7-dev:arm64 (7.5.0-6ubuntu2) ...
zyl@zyl:~$ sudo apt-get install g++-7
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  gcc-7-doc
The following NEW packages will be installed:
  g++-7
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 8,076 kB of archives.
After this operation, 20.4 MB of additional disk space will be used.
Get:1 http://ports.ubuntu.com/ubuntu-ports focal/universe arm64 g++-7 arm64 7.5.0-6ubuntu2 [8,076 kB]
Fetched 8,076 kB in 6s (1,272 kB/s)                                            
Selecting previously unselected package g++-7.
(Reading database ... 156174 files and directories currently installed.)
Preparing to unpack .../g++-7_7.5.0-6ubuntu2_arm64.deb ...
Unpacking g++-7 (7.5.0-6ubuntu2) ...
Setting up g++-7 (7.5.0-6ubuntu2) ...
Processing triggers for man-db (2.9.1-1) ...
zyl@zyl:~$ g++-7 --version
g++-7 (Ubuntu/Linaro 7.5.0-6ubuntu2) 7.5.0
Copyright (C) 2017 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.

于是,g++-7 似乎就这样安装好了。终于解决。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值