Ubuntu – Failed installation of package breaks apt-get

aptcudanvidiapackage-management

I just installed Ubuntu 18.04 for the first time. Excited to play with some GPU codes, I installed CUDA via the deb (local) for 17.10 option, as described on the Nvidia CUDA page. I know 17.10 != 18.04, but I had read of people having success with this.

I followed the installation instructions provided by 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

The last command resulted in an error when installing 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)

Maybe I bit off more than I could chew, so I decided to move onto less challenging things. I proceeded to install some basic packages, such as git, but upon doing so, I got this error:

> 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).

Trying the suggested sudo apt --fix-broken install command results in the same nvidia-396 error encountered above.

It appears my attempted installation of cuda has put apt-get into a state such that it will no longer install or remove any packages, due to an unmet dependencies error. Worded more simply, installing cuda has broken apt-get completely.

How can I get my package manager working again?

Best Answer

I fix this issue only with:

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