将 wsl2 实例升级到 Ubuntu 20 LTS 后,无法安装 build-essential 等软件包

将 wsl2 实例升级到 Ubuntu 20 LTS 后,无法安装 build-essential 等软件包

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: gcc (>= 4:9.2) but it is not going to be installed
                   Depends: g++ (>= 4:9.2) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

如果深入挖掘

❯ sudo apt-get install -f libgcc-9-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:
 libgcc-9-dev : Depends: libitm1 (>= 9.3.0-10ubuntu2) but it is not going to be installed
                Depends: libatomic1 (>= 9.3.0-10ubuntu2) but it is not going to be installed
                Depends: liblsan0 (>= 9.3.0-10ubuntu2) but it is not going to be installed
                Depends: libtsan0 (>= 9.3.0-10ubuntu2) but it is not going to be installed
                Depends: libubsan1 (>= 9.3.0-10ubuntu2) but it is not going to be installed
                Depends: libquadmath0 (>= 9.3.0-10ubuntu2) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
❯ sudo apt-get install -f libasan5 libatomic1 libgcc-s1
Reading package lists... Done
Building dependency tree
Reading state information... Done
libgcc-s1 is already the newest version (10.1.0-2ubuntu1~18.04).
libgcc-s1 set to manually installed.
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:
 libatomic1 : Depends: gcc-10-base (= 10-20200411-0ubuntu1) but 10.1.0-2ubuntu1~18.04 is to be installed
E: Unable to correct problems, you have held broken packages.

如何解决这个依赖链问题?强制使用最新的软件包还是降级到推荐的版本?

答案1

正如@user535733提到的,降级容易得多。我设法降级所有依赖项并安装正确版本的 gcc。诀窍是利用aptitude,它提供的功能比 更丰富apt

sudo apt install aptitude
sudo aptitude update && sudo aptitude install build-essential

它给了我:

      Install the following packages:
1)      tcc [0.9.27-8 (focal)]

      Keep the following packages at their current version:
2)      build-essential [Not Installed]
3)      g++ [Not Installed]
4)      g++-9 [Not Installed]
5)      gcc [Not Installed]
6)      gcc-9 [Not Installed]
7)      libatomic1 [Not Installed]
8)      libgcc-9-dev [Not Installed]
9)      libitm1 [Not Installed]
10)     liblsan0 [Not Installed]
11)     libquadmath0 [Not Installed]
12)     libstdc++-9-dev [Not Installed]
13)     libtsan0 [Not Installed]
14)     libubsan1 [Not Installed]

哪一个不是我们想要的,所以输入n

然后 aptitude 会提出另一个解决方案,如下所示:

The following actions will resolve these dependencies:

     Downgrade the following packages:
1)     gcc-10-base [10.1.0-2ubuntu1~18.04 (now) -> 10-20200416-0ubuntu1 (focal)]
2)     libcc1-0 [10.1.0-2ubuntu1~18.04 (now) -> 10-20200416-0ubuntu1 (focal)]
3)     libgcc-s1 [10.1.0-2ubuntu1~18.04 (now) -> 10-20200416-0ubuntu1 (focal)]
4)     libgcc1 [1:10.1.0-2ubuntu1~18.04 (now) -> 1:10-20200416-0ubuntu1 (focal)]
5)     libgomp1 [10.1.0-2ubuntu1~18.04 (now) -> 10-20200416-0ubuntu1 (focal)]
6)     libstdc++6 [10.1.0-2ubuntu1~18.04 (now) -> 10-20200416-0ubuntu1 (focal)]



Accept this solution? [Y/n/q/?] Y

我们可以接受这个计划,然后确认安装。

Setting up build-essential (12.8ubuntu1) ...

当你看到上面那行字的时候,就完成了!恭喜你!

相关内容