Removing Nvidia CUDA Toolkit and installing new one

376,957

Solution 1

For removing cuda, Nvidia has prepared a file (I presume this is a standard method). You need to change your directory to the cuda's path, which is by default /usr/local/cuda-x.y/bin; where x.y is your cuda version, you can do this by using the below command: (I have cuda 9.0=x.y)

 cd /usr/local/cuda-9.0/bin

There is a file named uninstall_cuda_9.0.pl in this directory (please note that the cuda version is 9.0, so run the uninstall_cuda_9.0.pl to remove cuda completely from your system!

chmod +x uninstall_cuda_9.0.pl
sudo ./uninstall_cuda_9.0.pl

As soon as you enter your password, the cuda files will be erased. (This may take a few minutes)

NOTE: How do you figure out which cuda has been installed on your Ubuntu system? By using the command nvcc, you can see that my cuda version is 9.0 in the last line of the nvcc result.

nvcc --version

The result will look like this:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Sep__1_21:08:03_CDT_2017
Cuda compilation tools, release 9.0, V9.0.176 

Note that the above method works if you set $PATH variable correctly, So if your nvcc command not works then please use the below command in terminal to find cuda version

ls /usr/local/ | grep cuda

UPDATE

I have installed cuda 10.2 on my system and it seems that there isn't uninstall_cuda_x.x.pl file, but nvidia replaced this file by cuda-uninstaller file in the same directory.

Solution 2

Make sure the method you use to install cuda toolkit. This answer is for whom use deb files to install cuda. I have no idea if this works for .run files.

sudo apt-get autoremove --purge cuda 

This can clear the cuda toolkit clearly. You can check that the folder /usr/local/cuda gone. And this command is the best choice to remove apt installed app.

But when you reinstall another version of cuda, you must use:

sudo apt-get install cuda-x.x

the version number must be included. I tried to install another version of cuda after the remove of the previous version, I find that sudo apt-get install cuda will still install the previous one.

Solution 3

For CUDA 10.1 or newer, try:

sudo /usr/local/cuda/bin/cuda-uninstaller

For CUDA 10.0, try:

sudo  /usr/local/cuda/bin/uninstall_cuda_10.0.pl

Solution 4

Try:

sudo apt-get --purge -y remove 'cuda*'
sudo apt-get --purge -y remove 'nvidia*'
sudo reboot

It removes any installed cuda and nvidia packages and then you can install any specific version that you like from: https://developer.nvidia.com/cuda-toolkit-archive.

Solution 5

One should NOT, unlike suggested in among others the accepted answer, manually remove files that were installed with apt (from some ppa, or nvidia repository).

The correct way to uninstall just cuda and keep your nvidia drivers would be:

sudo apt purge "libcublas*" "cuda-*" cuda

Possible, because they were installed as requirements, you can also purge,

sudo apt purge "nsight-*" nvidia-modprobe

After that you can, if you want, also remove the nvidia drivers with:

sudo apt purge "*nvidia*"

Of course, if you installed cuda using nvidia's .run file then this won't work; in that case you probably have some uninstall script.

Share:
376,957

Related videos on Youtube

tomtom
Author by

tomtom

Updated on September 18, 2022

Comments

  • tomtom
    tomtom almost 2 years

    I installed the CUDA 5.5 package on Ubuntu 14.04 (which is not supported for this version of Ubuntu version) , and I didn't do it well.

    I want to remove what I've installed earlier and install a new CUDA 6.5 toolkit,

    After typing this in the terminal: dpkg -l | grep -i nvidia,

    I get the following output:

    ii  bbswitch-dkms                                         0.8-1~trustyppa1                                    all          Interface for toggling the power on NVIDIA Optimus video cards
    ii  bumblebee                                             3.2.1-90~trustyppa1                                 amd64        NVIDIA Optimus support
    ii  bumblebee-nvidia                                      3.2.1-90~trustyppa1                                 amd64        NVIDIA Optimus support using the proprietary NVIDIA driver
    ii  libcublas5.5:amd64                                    5.5.22-3ubuntu1                                     amd64        NVIDIA CUDA BLAS runtime library
    ii  libcuda1-331                                          331.38-0ubuntu7.1                                   amd64        NVIDIA CUDA runtime library
    ii  libcudart5.5:amd64                                    5.5.22-3ubuntu1                                     amd64        NVIDIA CUDA runtime library
    ii  libcufft5.5:amd64                                     5.5.22-3ubuntu1                                     amd64        NVIDIA CUDA FFT runtime library
    ii  libcufftw5.5:amd64                                    5.5.22-3ubuntu1                                     amd64        NVIDIA CUDA FFTW runtime library
    ii  libcuinj64-5.5:amd64                                  5.5.22-3ubuntu1                                     amd64        NVIDIA CUDA INJ runtime library (64-bit)
    ii  libcurand5.5:amd64                                    5.5.22-3ubuntu1                                     amd64        NVIDIA CUDA Random Numbers Generation runtime library
    ii  libcusparse5.5:amd64                                  5.5.22-3ubuntu1                                     amd64        NVIDIA CUDA Sparse Matrix runtime library
    ii  libnppc5.5:amd64                                      5.5.22-3ubuntu1                                     amd64        NVIDIA Performance Primitives core runtime library
    ii  libnppi5.5:amd64                                      5.5.22-3ubuntu1                                     amd64        NVIDIA Performance Primitives for image processing runtime library
    ii  libnpps5.5:amd64                                      5.5.22-3ubuntu1                                     amd64        NVIDIA Performance Primitives for signal processing runtime library
    ii  libnvtoolsext1:amd64                                  5.5.22-3ubuntu1                                     amd64        NVIDIA Tools Extension
    ii  libnvvm2:amd64                                        5.5.22-3ubuntu1                                     amd64        NVIDIA CUDA Compiler NVVM runtime library
    ii  nvidia-331                                            331.38-0ubuntu7.1                                   amd64        NVIDIA binary driver - version 331.38
    ii  nvidia-cuda-dev                                       5.5.22-3ubuntu1                                     amd64        NVIDIA CUDA development files
    ii  nvidia-cuda-doc                                       5.5.22-3ubuntu1                                     all          NVIDIA CUDA and OpenCL documentation
    ii  nvidia-cuda-gdb                                       5.5.22-3ubuntu1                                     amd64        NVIDIA CUDA GDB
    ii  nvidia-cuda-toolkit                                   5.5.22-3ubuntu1                                     amd64        NVIDIA CUDA toolkit
    ii  nvidia-libopencl1-331                                 331.38-0ubuntu7.1                                   amd64        NVIDIA OpenCL Driver and ICD Loader library
    ii  nvidia-nsight                                         5.5.22-3ubuntu1                                     amd64        NVIDIA Nsight Eclipse Edition
    ii  nvidia-opencl-dev:amd64                               5.5.22-3ubuntu1                                     amd64        NVIDIA OpenCL development files
    ii  nvidia-opencl-icd-331                                 331.38-0ubuntu7.1                                   amd64        NVIDIA OpenCL ICD
    ii  nvidia-profiler                                       5.5.22-3ubuntu1                                      amd64        NVIDIA Profiler for CUDA and OpenCL
    ii  nvidia-settings                                       331.20-0ubuntu8                                     amd64        Tool for configuring the NVIDIA graphics driver
    ii  nvidia-visual-profiler                                5.5.22-3ubuntu1                                     amd64        NVIDIA Visual Profiler
    ii  primus
    

    I'd like to remove only what is needed to install the newest CUDA toolkit. Packages, like bumblebee, I want to remain as they are.

    Which packages should I remove and which should not be removed to get this done?

  • kRazzy R
    kRazzy R over 6 years
    for me this sudo ./uninstall_cuda_9.0.pl file is not there what to do?
  • coolscitist
    coolscitist about 6 years
    Should be sudo apt-get install x-x eg: sudo apt-get install cuda-9-0
  • Moonlight Knight
    Moonlight Knight about 6 years
    @coolscitist Thanks for your comment. Both works. I have checked.
  • GyuHyeon Choi
    GyuHyeon Choi about 6 years
    shouldn't it be something like cuda*? E.g., $ sudo apt-get --purge remove cuda*
  • Moonlight Knight
    Moonlight Knight about 6 years
    @GyuHyeonChoi Good suggestion. Did that work for you? If it is, that's a good option.
  • smerllo
    smerllo almost 5 years
    Thank you. Small details in your answer saved my time.
  • Thomas Ward
    Thomas Ward over 4 years
    Please don't post the same answer to multiple posts. If the questions are similar to each other and similar enough to be duplicates, please flag them as duplicates rather than reposting the same answer to multiple questions verbatim.
  • Bobbi Bennett
    Bobbi Bennett over 4 years
    cuda 10.2 does not have either uninstall-cuda* or cuda-uninstaller. At least, I do not find them.
  • Carlo Wood
    Carlo Wood over 4 years
    This misses libcublas*.
  • GR4
    GR4 about 4 years
    @GyuHyeonChoi Indeed it was necessary for me to use cuda*
  • Panagiotis Simakis
    Panagiotis Simakis about 4 years
    @BobbiBennett Try the first command
  • Panagiotis Simakis
    Panagiotis Simakis about 4 years
    Such a brave man :P
  • Silicomancer
    Silicomancer about 3 years
    In 11.2 there also seems to be no "cuda-uninstaller" in "bin".
  • Silicomancer
    Silicomancer about 3 years
    Both do not exists for 11.2.
  • Tare
    Tare over 2 years
    for cuda 11.2 it is supposed to be /usr/local/cuda-11.2/bin/cuda-uninstaller (i.e. in the bin folder), according to the installation guide. i can't find it myself though. see docs.nvidia.com/cuda/cuda-installation-guide-linux/… section 2.8