Cannot Purge and Install NVIDIA driver

Hi All, I’m a beginner in here. I’m trying to install NVIDIA driver 384 and CUDA 7.5/8.0.

So the fisrt step that I took :

sudo apt-get purge nvidia*

and the result was like this :

You might want to run ‘apt-get -f install’ to correct these:
The following packages have unmet dependencies:
cuda-cudart-dev-8-0 : Depends: cuda-driver-dev-8-0 but it is not going to be installed
cuda-cufft-dev-8-0 : Depends: cuda-cufft-8-0 (>= 8.0.61) but it is not going to be installed
cuda-cusolver-dev-8-0 : Depends: cuda-cusolver-8-0 (>= 8.0.61) but it is not going to be installed
cuda-cusparse-dev-8-0 : Depends: cuda-cusparse-8-0 (>= 8.0.61) but it is not going to be installed
cuda-drivers : Depends: nvidia-384 (>= 384.111) but it is not going to be installed
Depends: nvidia-384-dev (>= 384.111) but it is not going to be installed
Depends: nvidia-modprobe (>= 384.111) but it is not going to be installed
Depends: nvidia-settings (>= 384.111) but it is not going to be installed
Depends: nvidia-opencl-icd-384 (>= 384.111) but it is not going to be installed
cuda-npp-dev-8-0 : Depends: cuda-npp-8-0 (>= 8.0.61) but it is not going to be installed
cuda-nvgraph-dev-8-0 : Depends: cuda-nvgraph-8-0 (>= 8.0.61) but it is not going to be installed
cuda-nvrtc-dev-8-0 : Depends: cuda-nvrtc-8-0 (>= 8.0.61) but it is not going to be installed
cuda-runtime-8-0 : Depends: cuda-nvrtc-8-0 (>= 8.0.61) but it is not going to be installed
Depends: cuda-nvgraph-8-0 (>= 8.0.61) but it is not going to be installed
Depends: cuda-cusolver-8-0 (>= 8.0.61) but it is not going to be installed
Depends: cuda-cufft-8-0 (>= 8.0.61) but it is not going to be installed
Depends: cuda-cusparse-8-0 (>= 8.0.61) but it is not going to be installed
Depends: cuda-npp-8-0 (>= 8.0.61) but it is not going to be installed
cuda-samples-8-0 : Depends: cuda-driver-dev-8-0 but it is not going to be installed
cuda-toolkit-8-0 : Depends: cuda-nvml-dev-8-0 (>= 8.0.61) but it is not going to be installed
Depends: cuda-driver-dev-8-0 (>= 8.0.61) but it is not going to be installed
cuda-visual-tools-8-0 : Depends: cuda-driver-dev-8-0 but it is not going to be installed
Depends: cuda-nvml-dev-8-0 but it is not going to be installed
libcuda1-384 : Depends: nvidia-384 but it is not going to be installed
E: Unmet dependencies. Try ‘apt-get -f install’ with no packages (or specify a solution).

I’ve also tried to sudo apt-get -f install
The result was :
Unpacking cuda-nvgraph-8-0 (8.0.61-1) …
dpkg: error processing archive /var/cache/apt/archives/cuda-nvgraph-8-0_8.0.61-1_amd64.deb (–unpack):
trying to overwrite ‘/usr/local/cuda-8.0/lib64’, which is also in package cuda-cudart-8-0 8.0.61-1
No apport report written because MaxReports is reached already
Errors were encountered while processing:
/var/cache/apt/archives/cuda-driver-dev-8-0_8.0.61-1_amd64.deb
/var/cache/apt/archives/cuda-nvrtc-8-0_8.0.61-1_amd64.deb
/var/cache/apt/archives/cuda-cusolver-8-0_8.0.61-1_amd64.deb
/var/cache/apt/archives/cuda-cufft-8-0_8.0.61-1_amd64.deb
/var/cache/apt/archives/cuda-cusparse-8-0_8.0.61-1_amd64.deb
/var/cache/apt/archives/cuda-npp-8-0_8.0.61-1_amd64.deb
/var/cache/apt/archives/cuda-nvml-dev-8-0_8.0.61-1_amd64.deb
/var/cache/apt/archives/cuda-nvgraph-8-0_8.0.61-1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

Is there any solution for this ? Thank you very much before

1 Like

You have to exit the GUI first.

How to fix NVIDIA driver failure on Ubuntu – Code Yarns
[url]https://codeyarns.com/2013/02/07/how-to-fix-nvidia-driver-failure-on-ubuntu/[/url]

shortcut keys - Switching Between GUI and Terminal - Ask Ubuntu
[url]https://askubuntu.com/questions/292069/switching-between-gui-and-terminal/292076[/url]

Hi JGB123321, Thank you for answering!

Btw, I didn’t use the GUI in the first place since I’m working on server.

Luckily, I have already solved the problem by removing all nvidia and cuda manually , like this :

sudo dpkg --force-all -P nvida- (have to remove all nvidia-
and cuda-
one by one since I can not use : sudo apt-get purge nvidia*)

After removing all package related to nvidia and cuda, I re-installed nvidia driver like this :
sudo add-apt-repository ppa:graphics-drivers
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install nvidia-384-dev
sudo reboot
to check the result :
lsmod | grep nvidia
nvidia-smi

For cuda, I followed the instruction in this link http://www.r-tutor.com/gpu-computing/cuda-installation/cuda7.5-ubuntu.

Once again, thank you very much for your support and attention. I really appreciate that. ^^

1 Like

Iman - thank you so much for posting your resolution to this. Ran into this on Ubuntu 18.04.

Also can confirm this has nothing to do with exiting the GUI as I encountered these errors in tty2, after killing lightdm.

I was going absolutely nuts as I was stuck in the same situation as you - I couldn’t run ‘sudo apt-get remove --purge nvidia-*’ as I’d get a ton of these dependency errors, and if I tried to run ‘sudo apt-get -f install’ I’d get the same “Sub-process /usr/bin/dpkg returned an error code (1)” message as you.

In case it’s not 100% clear from Iman’s post, as it took me some time to understand what they meant - what you have to do is run

sudo dpkg --force-all -P [name of package with unmet dependency]

one by one until you’ve removed all the offending packages with unmet dependencies. So for example based on Iman’s errors you’d do

sudo dpkg --force-all -P cuda-cudart-dev-8-0

then

sudo dpkg --force-all -P cuda-cufft-dev-8-0

then

sudo dpkg --force-all -P cuda-cusolver-dev-8-0

etc etc until you’ve made your way down the whole list. Once all the packages with missing dependencies are all gone you can finally run the ‘sudo apt-get remove --purge nvidia-*’ command again, and it’ll succeed this time. You can then do a clean install of whatever CUDA/NVIDIA driver you need.

Couldn’t find anything about this on StackOverflow or Github…so glad you made this thread, was afraid I’d just have to do a fresh Ubuntu install…thanks again Iman!! :)

1 Like

Hi Casey,

I’m happy if you solved the problem. Your examples are totally right.

Thank you very much for the detail and clearer explanation of the solution.^^

I really appriciate it. You saved me man :))

Hello Iman,

Thank you for suggesting this, I was install drivers for Nvidia M4000 on Linux 20.04. However, I am faced with “Sub-process /usr/bin/dpkg returned an error code (1)” I have tried purging and removing the files and restart the installation but I am always met with this error. My understanding of Linux is very very low, so any help in this direction will be appreciated.
Thanks,
MB