40

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?

30

This method will give a complete removal of Cuda:

Simple

remove the CUDA files in /usr/local/cuda-5.0


Advanced


Uninstall just nvidia-cuda-toolkit

sudo apt-get remove nvidia-cuda-toolkit

Uninstall nvidia-cuda-toolkit and it's dependencies

sudo apt-get remove --auto-remove nvidia-cuda-toolkit

Purging config/data

sudo apt-get purge nvidia-cuda-toolkit or sudo apt-get purge --auto-remove nvidia-cuda-toolkit

Additionally, delete the /opt/cuda and ~/NVIDIA_GPU_Computing_SDK folders if they are present. and remove the export PATH=$PATH:/opt/cuda/bin and export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/cuda/lib:/opt/cuda/lib64 lines of the ~/.bash_profile file

| improve this answer | |
  • 2
    This does not remove the files for me. In fact, is seems as if the usual removal does not clean up remaining kernel modules… – e-sushi Apr 4 '15 at 23:14
  • @marbel is there a better way? – Nathan Apr 11 '18 at 18:14
  • @marbel, can you explain why we shouldn't use apt-get? – Nagabhushan S N Jan 14 '19 at 6:46
  • @marbel saying that "this is a terrible answer" or "Just google", is the worst kind of responses that I have ever seen. If this is a terrible answer, then explain why you think so! And btw, how do you think people got here? By googling, my friend. – Azim Aug 20 '19 at 15:01
  • You can find some answers in the nvidia forums. The "solutions" change so often that it's hard to find something reliable. For me the solution at the time was to reinstall the OS and I found this advice in the nvidia forums. – marbel Aug 20 '19 at 16:49
24

Nvidia has prepared a file for removing cuda (I guess this method is standard one).First of all change directory to cuda path,which in default ,it is /usr/local/cuda-x.y/bin which x.y is your cuda version, you can change the directory with using the below command:(I have cuda 9.0=x.y)

 cd /usr/local/cuda-9.0/bin

In this directory there is a file which it's name is uninstall_cuda_9.0.pl(please pay attention that my cuda version is 9.0) , so you just need to run 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

After entering your password the cuda files are going to erase . ( it may take a few minutes to complete)

NOTE: How to know which cuda has installed in your ubuntu? You can check it by the nvcc command, in the last line of the nvcc result you can see that my cuda version is 9.0

nvcc --version

result of this command will be like as below:

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.

| improve this answer | |
  • 20
    for me this sudo ./uninstall_cuda_9.0.pl file is not there what to do? – kRazzy R Feb 18 '18 at 19:00
23

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.

| improve this answer | |
  • Should be sudo apt-get install x-x eg: sudo apt-get install cuda-9-0 – coolscitist Jun 18 '18 at 16:55
  • @coolscitist Thanks for your comment. Both works. I have checked. – Moonlight Knight Jun 19 '18 at 0:58
  • 3
    shouldn't it be something like cuda*? E.g., $ sudo apt-get --purge remove cuda* – GyuHyeon Choi Jun 21 '18 at 6:45
  • @GyuHyeonChoi Good suggestion. Did that work for you? If it is, that's a good option. – Moonlight Knight Jun 23 '18 at 8:49
  • Thank you. Small details in your answer saved my time. – Soufiane Chami Jul 1 '19 at 1:53
6

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
| improve this answer | |
  • cuda 10.2 does not have either uninstall-cuda* or cuda-uninstaller. At least, I do not find them. – Bobbi Bennett Jan 23 at 17:36
  • 1
    @BobbiBennett Try the first command – Panagiotis Simakis May 20 at 9:32
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.

| improve this answer | |
  • 1
    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. – Thomas Ward Oct 14 '19 at 14:28
  • This misses libcublas*. – Carlo Wood Mar 14 at 21:45
1

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.

| improve this answer | |
0

Please refer the link below, which would help you decide whether your new installation and old installation of CUDA would be conflicting or not. If they aren't conflicting, you should be able to keep both of them.

If there is already a version of CUDA installed, you can do the following:

The method of uninstalling directly depends on the method of installation, whether it was a runfile, or a deb file, etc.

Use the following command to uninstall a Toolkit runfile installation:

$ sudo /usr/local/cuda-X.Y/bin/uninstall_cuda_X.Y.pl

Use the following command to uninstall a Driver runfile installation:

$ sudo /usr/bin/nvidia-uninstall

Use the following commands to uninstall a Deb installation:

$ sudo apt-get --purge remove <package_name>

Nvidia conflicting installations

| improve this answer | |
0

To remove packages without interruption (aggressive way) because there is no way others doing it.

PKG="something" ## in our case its Nvidia or/and CUDA 
for item in `dpkg -i grep ${PGK} | awk '{print $2}'` ; do dpkg --remove --force-all $item ; done 

It will remove the packages without any issues.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.