如何修复 ubuntu 18.04 LTS 上的这个 apt 问题?

如何修复 ubuntu 18.04 LTS 上的这个 apt 问题?

系统更新错误信息: 包装系统坏了 检查您是否正在使用第三方存储库。如果是,请禁用它们,因为它们是问题的常见来源。此外,在终端中运行以下命令:apt-get install -f 当我尝试时,sudo apt-get istall -f我收到一条错误消息:

(Reading database ... 172407 files and directories currently installed.)
Preparing to unpack .../libnvidia-gl-390_390.59-0ubuntu0~gpu18.04.1_i386.deb ...
diversion of /usr/lib/i386-linux-gnu/libGL.so.1 to /usr/lib/i386-linux-gnu/libGL.so.1.distrib by nvidia-340
dpkg-divert: error: mismatch on package
  when removing 'diversion of /usr/lib/i386-linux-gnu/libGL.so.1 by libnvidia-gl-390'
  found 'diversion of /usr/lib/i386-linux-gnu/libGL.so.1 to /usr/lib/i386-linux-gnu/libGL.so.1.distrib by nvidia-340'
dpkg: error processing archive /var/cache/apt/archives/libnvidia-gl-390_390.59-0ubuntu0~gpu18.04.1_i386.deb (--unpack):
 new libnvidia-gl-390:i386 package pre-installation script subprocess returned error exit status 2
Preparing to unpack .../libnvidia-gl-390_390.59-0ubuntu0~gpu18.04.1_amd64.deb ...
diversion of /usr/lib/x86_64-linux-gnu/libGL.so.1 to /usr/lib/x86_64-linux-gnu/libGL.so.1.distrib by nvidia-340
dpkg-divert: error: mismatch on package
  when removing 'diversion of /usr/lib/x86_64-linux-gnu/libGL.so.1 by libnvidia-gl-390'
  found 'diversion of /usr/lib/x86_64-linux-gnu/libGL.so.1 to /usr/lib/x86_64-linux-gnu/libGL.so.1.distrib by nvidia-340'
dpkg: error processing archive /var/cache/apt/archives/libnvidia-gl-390_390.59-0ubuntu0~gpu18.04.1_amd64.deb (--unpack):
 new libnvidia-gl-390:amd64 package pre-installation script subprocess returned error exit status 2
Errors were encountered while processing:
 /var/cache/apt/archives/libnvidia-gl-390_390.59-0ubuntu0~gpu18.04.1_i386.deb
 /var/cache/apt/archives/libnvidia-gl-390_390.59-0ubuntu0~gpu18.04.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

我怎样才能解决这个问题 ?

答案1

首先使用以下方法删除 .deb

sudo rm /var/cache/apt/archives/libnvidia-gl-390_390.59-0ubuntu0~gpu18.04.1_i386.deb

sudo rm /var/cache/apt/archives/libnvidia-gl-390_390.59-0ubuntu0~gpu18.04.1_amd64.deb

然后删除缓存中的所有下载文件。

sudo apt-get clean
sudo apt-get autoremove && sudo apt-get autoclean
sudo apt-get install -f
sudo apt-get update

最后尝试使用 sudo apt-get install 安装应用程序的新副本

答案2

错误消息的相关部分如下:

when removing 'diversion of /usr/lib/i386-linux-gnu/libGL.so.1 by libnvidia-gl-390'
  found 'diversion of /usr/lib/i386-linux-gnu/libGL.so.1 to /usr/lib/i386-linux-gnu/libGL.so.1.distrib by nvidia-340'

“Diversions” 是 dpkg 的东西。Nvidia-340 软件包必须创建这些转移,并且从未删除它们。要检查,请执行

dpkg-divert --list nvidia-340

它将列出每个指定的改道。

diversion of /usr/lib/x86_64-linux-gnu/libGL.so.1 to /usr/lib/x86_64-linux-gnu/libGL.so.1.distrib by nvidia-340
...

您可以通过将转移的文件名传递给(需要 root)来删除这些转移

dpkg-divert --remove /usr/lib/x86_64-linux-gnu/libGL.so.1

一旦您清理了旧的分歧,安装较新的 Nvidia 驱动程序包就apt应该可以成功。

相关内容