软件包安装失败导致 apt-get 崩溃

软件包安装失败导致 apt-get 崩溃

我刚刚首次安装了 Ubuntu 18.04。为了能够使用一些 GPU 代码,我通过deb (local)for17.10选项安装了 CUDA,如Nvidia CUDA 页面。我知道17.10 != 18.04,但我读过有人在这方面取得了成功。

我按照 Nvidia 提供的安装说明进行操作:

sudo dpkg -i cuda-repo-ubuntu1710-9-2-local_9.2.88-1_amd64.deb
sudo apt-key add /var/cuda-repo-<version>/7fa2af80.pub
sudo apt-get update
sudo apt-get install cuda

最后一个命令在安装时导致错误nvidia-396

Get:1 file:/var/cuda-repo-9-2-local  nvidia-396 396.26-0ubuntu1 [80.0 MB]
(Reading database ... 167630 files and directories currently installed.)
Preparing to unpack .../nvidia-396_396.26-0ubuntu1_amd64.deb ...
Unpacking nvidia-396 (396.26-0ubuntu1) ...
dpkg: error processing archive /var/cuda-repo-9-2-local/./nvidia-396_396.26-0ubuntu1_amd64.deb (--unpack):
 trying to overwrite '/usr/lib/x86_64-linux-gnu/libGLX_indirect.so.0', which is also in package libglx-mesa0:amd64 18.0.0~rc5-1ubuntu1
Errors were encountered while processing:
 /var/cuda-repo-9-2-local/./nvidia-396_396.26-0ubuntu1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

也许我承担了太多的事情,所以我决定做一些不那么有挑战性的事情。我继续安装一些基本的软件包,例如git,但这样做时,我得到了这个错误:

> sudo apt-get install git
Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 cuda-drivers : Depends: nvidia-396 (>= 396.26) but it is not going to be installed
 git : Depends: liberror-perl but it is not going to be installed
       Depends: git-man (> 1:2.17.1) but it is not going to be installed
       Depends: git-man (< 1:2.17.1-.) but it is not going to be installed
 libcuda1-396 : Depends: nvidia-396 (>= 396.26) but it is not going to be installed
 nvidia-396-dev : Depends: nvidia-396 (>= 396.26) but it is not going to be installed
 nvidia-opencl-icd-396 : Depends: nvidia-396 (>= 396.26) but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

尝试建议的sudo apt --fix-broken install命令会导致nvidia-396上述相同的错误。

看来我尝试安装的程序cuda已经进入了apt-get无法再安装或删除任何软件包的状态,因为存在未满足的依赖关系错误。简而言之,安装cudaapt-get完全中断。

我怎样才能让我的包管理器再次工作?

答案1

我仅通过以下方法修复了此问题:

sudo apt-get -o Dpkg::Options::="--force-overwrite" install --fix-broken

答案2

与 StrugglingProgrammer 的命令类似,我必须确保卸载全部cuda 包(例如 cuda-demo*)

您可以通过以下方式检查其中哪些可能:

dpkg -l | grep -i cuda
dpkg -l | grep -i nvidia

所以也许可以尝试一下

sudo apt-get remove --purge cuda-* libcuda* nvidia* 

(针对整个批次)或者更具体地选择:

sudo apt-get remove --purge cuda-drivers libcuda* cuda-runtime* cuda-8-0 cuda-demo*

对我来说具体来说(在尝试安装cuda-8-0和失败后libcudnn6)它是:

sudo apt-get remove --purge nvidia* cuda-drivers libcuda* cuda-runtime* cuda-8-0 cuda-demo*

希望这可以有所帮助。

答案3

我通过使用单个apt-get remove命令删除所有已安装的内容来解决这个问题:

sudo apt-get remove --purge nvidia* cuda-drivers libcuda1-396 cuda-runtime-9-2 cuda-9.2 cuda-demo-suite-9-2  cuda

答案4

我执行了

sudo add-apt-repository ppa:graphics-drivers
sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
sudo bash -c 'echo "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda.list'
sudo bash -c 'echo "deb http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda_learn.list'

(b)安装 CUDA 10.1 软件包,包括 CuDNN 库

sudo apt update
sudo apt install cuda-10-1
sudo apt install libcudnn7

检查一下关联我没有删除任何驱动程序,只是安装了上面的东西并更新了.profile

nano ~/.profile
# set PATH for cuda 10.1 installation
if [ -d "/usr/local/cuda-10.1/bin/" ]; then
    export PATH=/usr/local/cuda-10.1/bin${PATH:+:${PATH}}
    export LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
fi

相关内容