How to remove cuda completely from ubuntu?
Asked Answered
P

7

92

I have ubuntu 18.04, and accidentally installed cuda 9.1 to run Tensorflow-gpu, but it seems tensorflow-gpu requires cuda 10.0, so I want to remove cuda first by executing:

martin@nlp-server:~$ sudo apt-get remove --auto-remove nvidia-cuda-toolkit
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-libraries-dev-10-1 : Depends: libcublas-dev (>= 10.2.0.168) but 10.1.0.105-1 is to be installed
 cuda-samples-10-1 : Depends: libcublas-dev (>= 10.2.0.168) but 10.1.0.105-1 is to be installed
 cuda-visual-tools-10-1 : Depends: libcublas-dev (>= 10.2.0.168) but 10.1.0.105-1 is to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

Then I tried to run 'apt --fix-broken install', but got the following error:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  libcublas-dev
The following packages will be upgraded:
  libcublas-dev
1 upgraded, 0 newly installed, 0 to remove and 145 not upgraded.
69 not fully installed or removed.
Need to get 0 B/39.1 MB of archives.
After this operation, 3,458 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 253408 files and directories currently installed.)
Preparing to unpack .../libcublas-dev_10.2.0.168-1_amd64.deb ...

Unpacking libcublas-dev (10.2.0.168-1) over (10.1.0.105-1) .........................................................................................................................................................................................................................................................] 
dpkg: error processing archive /var/cache/apt/archives/libcublas-dev_10.2.0.168-1_amd64.deb (--unpack):
 trying to overwrite '/usr/lib/x86_64-linux-gnu/libcublas_static.a', which is also in package nvidia-cuda-dev 9.1.85-3ubuntu1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/libcublas-dev_10.2.0.168-1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

How to remove cuda completely?

Phelloderm answered 3/6, 2019 at 16:44 Comment(1)
you can install multiple versions of CUDA alongside. Place them in different folders and set you CUDA_HOME in .bashrcMealtime
R
183

From cuda 11.4 onwards, an uninstaller script has been provided. Use it for the uninstallation:

# To uninstall cuda
sudo /usr/local/cuda-11.4/bin/cuda-uninstaller 
# To uninstall nvidia
sudo /usr/bin/nvidia-uninstall

If you are using cuda 11.3 or earlier refer to the section below for how to remove it.

If you get the problem of broken packages, it has happened since you added repo to the apt/sources.lst. Run the following to delete it:

sudo vim /etc/apt/sources.list

Go to the line containing reference to Nvidia repo and comment it by appending # in front of the line, for e.g.:

#deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /

Then run

sudo apt-get update 

This will fix the problem.

Removing Cuda 11.3 and earlier

There are two things- nvidia drivers and cuda toolkit- which you may want to remove. If you have installed using apt-get use the following to remove the packages completely from the system:

To remove cuda toolkit:

sudo apt-get --purge remove "*cublas*" "cuda*" "nsight*" 

To remove Nvidia drivers:

sudo apt-get --purge remove "*nvidia*"

If you have installed via source files (assuming the default location to be /usr/local) then remove it using:

sudo rm -rf /usr/local/cuda*

References: Nvidia uninstallation

Raouf answered 9/6, 2020 at 6:9 Comment(6)
Hi , even this "sudo apt-get --purge remove "cublas" "cuda*" "nsight*" " for me states that E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).Loella
Try first : sudo apt --fix-broken install. If that doesn't work may be you have added Nividia repo and need to comment it out. Check the part of the post where it says comment out the line in /etc/apt/sources.list and do a update.Raouf
I completely removed apt reinstalled it and then tried "sudo apt --fix-broken install" it worked. Yeah I commented that out eventhough I didn't get itLoella
FYI - /usr/local/cuda-11.4/bin/cuda-uninstaller is not available if you installed as local/remote repository which is the most common way. Also, probably should also add nccl* and cuda_learn*.Stansbury
If you install cuda using .deb file then you will not have cuda-uninstaller. Use sudo apt-get --purge remove "*cublas*" "*cufft*" "*curand*" \ "*cusolver*" "*cusparse*" "*npp*" "*nvjpeg*" "cuda*" "nsight*" Stansbury
I have just found that for cuda 11.1 there is the uninstaller as well: /usr/local/cuda-11.1/bin/cuda-uninstallerMauve
L
88

I solved this issue as follow :

sudo apt-get purge nvidia*
sudo apt-get autoremove
sudo apt-get autoclean
sudo rm -rf /usr/local/cuda*

This will do the job .

Lemmie answered 30/6, 2019 at 19:43 Comment(6)
In my case I had to purge everything cuda related, not nvidia related. Other than that, it worked.Hearsh
I may try that next and see. ThanksLemmie
@DimitrisKaramanis feel free to share how did you purge everything cuda related. I have sudo apt-get purge cuda*, if you've done it differently I can update the answer.Lemmie
That's exactly what I did, I replaced nvidia* with cuda*Hearsh
This did not suffice for me (neither nvidia nor cuda removal solved the broken dpkg state)Moulding
Careful with this command, the purge will also remove your NVIDIA driverJehius
C
14

Go to - /usr/local/cuda-10.2/bin

Run sudo ./cuda-uninstaller

Check all the options and then it will be uninstalled automatical

Conlen answered 26/12, 2019 at 9:9 Comment(3)
I think because this will not "clean" uninstall the cuda. After I used and reinstall CUDA, there was a notice "Existing package manager installation of the driver found...".Medullated
If NVidia says this is the correct solution, upvote. If it doesn't show up on your system, that doesn't invalidate Nvidia saying this is the correct way to use their own product.Lauree
The uninstaller file only exists if you installed fun a run file. Not if you installed from a package manager.Rompers
A
12

To remove CUDA Toolkit:

$ sudo apt-get --purge remove "*cublas*" "*cufft*" "*curand*" \
 "*cusolver*" "*cusparse*" "*npp*" "*nvjpeg*" "cuda*" "nsight*" 

To remove NVIDIA Drivers:

$ sudo apt-get --purge remove "*nvidia*"

To clean up the uninstall:

$ sudo apt-get autoremove

Source : NVIDIA installation guide

Alcoholicity answered 21/11, 2020 at 18:27 Comment(0)
S
6

Here is bit more complete answer. NVidia cuda installers are truly messy things. Different versions have different way and even within same version it depends on how did you installed.

Below works for 11.8 and higher installed using deb file.

# Below nvidia-* and libnvidia-* removes drivers also. Better to remove everything and reinstall. The libcudnn8* removed cuDNN.
sudo apt-get --purge remove cuda-* nvidia-* gds-tools-* libcublas-* libcufft-* libcufile-* libcurand-* libcusolver-* libcusparse-* libnpp-* libnvidia-* libnvjitlink-* libnvjpeg-* nsight* nvidia-* libnvidia-* libcudnn8*

# Also run below which gets rid of CUDA 10 and prior stuff.
sudo apt-get --purge remove "*cublas*" "*cufft*" "*curand*" "*cusolver*" "*cusparse*" "*npp*" "*nvjpeg*" "cuda*" "nsight*"

# Cleanup uninstall
sudo apt-get autoremove
sudo apt-get autoclean

# remove cuda directories
sudo rm -rf /usr/local/cuda*

# remove from dpkg
sudo dpkg -r cuda
sudo dpkg -r $(dpkg -l | grep '^ii  cudnn' | awk '{print $2}')
Stansbury answered 31/8, 2023 at 6:42 Comment(0)
W
5

In the official NVIDIA documentation, it was indicated how to permanently remove all drivers, including the CUDA Toolkit

Here is the link to the documentation - https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#removing-cuda-toolkit-and-driver


In order to uninstall CUDA Toolkit, you need to run this command:

sudo apt-get --purge remove "*cuda*" "*cublas*" "*cufft*" "*cufile*" "*curand*" \
 "*cusolver*" "*cusparse*" "*gds-tools*" "*npp*" "*nvjpeg*" "nsight*" "*nvvm*"

To remove NVIDIA drivers:

sudo apt-get --purge remove "*nvidia*" "libxnvctrl*"

To clean up the uninstall:

sudo apt-get autoremove
Worshipful answered 27/4, 2024 at 16:18 Comment(0)
E
0

Synaptic Menager help remove everything from linux

Envy answered 26/6, 2024 at 9:23 Comment(3)
Synaptic is not a bad tool to use for doing this task.Focalize
Welcome to Stack Overflow! Your answer could be improved with additional supporting information. If possible, please edit your post to add further details, such as explanations or documentation, so that others can understand how to solve the problem. You can find more information in How do I write a good answer? - "Brevity is acceptable, but fuller explanations are better." It might be helpful to review some highly upvoted answers as examples to follow. Thanks!Rosinarosinante
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Liquesce

© 2022 - 2025 — McMap. All rights reserved.