I've been working on installing CUDA for TensorFlow usage.

I realized that cuda-9.0 has been just released today, and I accidentally downloaded and dpkged it, and installed it on my machine.

I realized that cuda-9.0 is not yet compatible with TensorFlow so I had to uninstall it with:

sudo apt autoremove cuda

Which did remove everything, but now whenever I try to install cuda-8.0, after downloading and dpkging, it prompts me to install cuda-9.0 instead.

Now I know I can work around this with:

sudo apt-get install cuda-8-0

But I also need to install the patch, which can't be done this way.

I've been trying many methods to resolve this issue:

  1. sudo apt-get remove cuda-9-0-blablal
  2. Removing the apt-key of cuda-9 with:
    • apt-key del [KEY]

But none of these really worked.

Can someone help me out?


Right after posting this, I figured out the answer, which turned out to be simple.

I'm leaving it for others:

I was able to solve it simply, by removing cuda-9 stuff from /etc/apt/sources.list.d/cuda-9-0-local.list

UPDATE 2 And now I have another problem which is after

sudo dpkg -i cuda-8-0-blabla

none of it appears on sources.list.d anymore.

  • 1
    Actually, I was able to solve it simply, by removing cuda-9 stuff from /etc/apt/sources.list.d/cuda-9-0-local.list
    – Jay Shin
    Sep 27, 2017 at 7:58

7 Answers 7


I got the exact same issue and managed to fix it. First observation was that the cuda-8 related entries in sources.list.d/ were commented out, but removing these and doing the dpkg --install of the cuda-8 repo did not repopulate the sources.list.d/ entries. What worked was to purge the 'dpkg' install (/var/cuda*) manually and doing the 'dpkg --install' again.

step by step:

  • dpkg -l | grep cuda- | awk '{print $2}' | xargs -n1 sudo dpkg --purge
  • dpkg --install cuda-repo-ubuntu*-8.0-local*.deb
  • sudo apt-get update
  • sudo apt-get install cuda
  • 1
    I had to first do, sudo apt-get --purge remove cuda and sudo apt autoremove, so as to remove Cuda 9. Then I installed Cuda 8 Nov 27, 2017 at 19:40
  • I guess the cuda-repo for all the versions is the same, because when I do "sudo dpkg -i cuda-repo-ubuntu1604_8.0.61-1_amd64.deb" then "sudo apt-get instll cuda" it tries to install version 9 still
    – dashesy
    Jun 1, 2018 at 17:54
  • 1
    had to use "apt-get install cuda-8.0" otherwise cuda-9 was always selected
    – dashesy
    Jun 1, 2018 at 18:35
  • saved my life!! Mar 14, 2019 at 4:12

There's actually a script in /usr/local/cuda-9.x/bin/ which performs the uninstall process for you.

  • 1
    What is the name of the script?
    – Magick
    Mar 20, 2018 at 11:22
  • @Magick I believe it should be something like /usr/local/cuda-9.2/bin/uninstall_cuda_9.2.pl. That's what this link says, but I don't have this file myself. Jun 13, 2018 at 19:23


It works for me. It might be helpful for you too.

  • In the end, I reinstalled Ubuntu.
    – Jay Shin
    Oct 3, 2017 at 11:59
  • This should provide with the actual commands in the answer not in a link. No matter how good a solution is it should be fully accessible from within SO.
    – Eypros
    Apr 12, 2019 at 7:34

I had to add "--force-all" to the purge command:

dpkg -l | grep cuda- | awk '{print $2}' | xargs -n1 sudo dpkg --purge --force-all

The above command

sudo apt-get install cuda-8-0

might have worked but does not any more! You must change it into the following line - it is an almost undetectable difference:

sudo apt-get install cuda-8.0

The ending is not "-0" but ".0"!


The official way is to run a uninstaller script:

Taken from nVidia documentation:

4.6. Uninstallation

To uninstall the CUDA Toolkit, run the uninstallation script provided in the bin directory of the toolkit. By default, go to /usr/local/cuda-9.1/bin and run

$ sudo ./uninstall_cuda_9.1.pl
  • I don't have any such file (cuda-10.2). Also I think this is only the official way when you installed cude using a .run file, not when you use a .deb package manager.
    – Carlo Wood
    Mar 14, 2020 at 21:42

As answered by @Beef earlier:

  1. dpkg -l | grep cuda- | awk '{print $2}' | xargs -n1 sudo dpkg --purge
  2. dpkg --install cuda-repo-ubuntu*-8.0-local*.deb
  3. sudo apt-get update
  4. sudo apt-get install cuda

It doesn't work now. I realized step 1 doesn't remove cuda completely. I still had to do:

  • sudo apt-get remove cuda-* in order to remove my cuda-9-1 version and others.

Additionally when you are using deb(network) version or the deb(local), on doing:

sudo apt-get install cuda

It lists down cuda-9-1 the latest drivers. Refer to here.

The step 4 in instruction shown by @beef should be instead:

sudo apt-get install cuda-8-0

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.