軟體包安裝失敗導致 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-0libcudnn6它是:

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

相關內容