How to install Cuda Toolkit 7.0 or 8 on Debian 8?

I know that Debian 8 comes with the option to download and install CUDA Toolkit 6.0 using apt-get install nvidia-cuda-toolkit, but how do you do this for CUDA toolkit version 7.0 or 8?

I tried installing using the Ubuntu installers, as described below:

sudo wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/cuda-repo-ubuntu1404_7.0-28_amd64.deb

dpkg -i cuda-repo-ubuntu1404_7.0-28_amd64.deb

sudo apt-get update

sudo apt-get install -y cuda

However it did not work and the following message was returned:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 cuda : Depends: cuda-7-0 (= 7.0-28) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
  • @nullgeppetto: Please try following the instructions in my answer below :-) – einpoklum Nov 6 '15 at 13:23
up vote 22 down vote accepted

The following instructions are valid for CUDA 7.0, 7.5, and several previous (and probably later) versions. As far as Debian distributions, they're valid for Jessie and Stretch and probably other versions. They assume an amd64 (x86_64) architecture, but you can easily adapt them for x86 (x86_32).

Installation prerequisites

  • g++ - You should use the newest GCC version supported by your version of CUDA. For CUDA 7.x this would be version 4.9.3, last of the 4.x line; for CUDA 8.0, GCC 5.x versions are supported. If your distribution uses GCC 5.x by default, use that, otherwise GCC 5.4.0 should do. Earlier versions are usable but I wouldn't recommend them, if only for the better modern-C++ feature support for host-side code.
  • gcc - comes with g++. I even think CMake might default to having nvcc invoke gcc rather than g++ in some cases with a -x switch (but not sure about this).
  • libGLU - Mesa OpenGL libraries (+ development files?)
  • libXi - X Window System Xinput extension libraries (+ development files?)
  • libXmu - X Window System "miscellaneous utilities" library (+ development files?)
  • Linux kernel - headers for the kernel version you're running.

If you want a list of specific packages, that depends on exactly which distribution, but try the following (for CUDA 7.x):

sudo apt-get install gcc g++ gcc-4.9 g++-4.9 libxi libxi6 libxi-dev libglu1-mesa libglu1-mesa-dev libxmu6 libxmu6-dev linux-headers-amd64 linux-source

And you might add some -dbg versions of those packages for debugging symbols.

I'm pretty sure this covers it all - but I might have missed something I just had installed already. Also, CUDA can work with clang, at least experimentally, but I haven't tried that.

Installing the CUDA kernel driver

  1. Go to NVIDIA's CUDA Downloads page.
  2. Choose Linux > x86_64 > Ubuntu , and then whatever latest version they have (at the time of writing: Ubuntu 15.04).
  3. Choose the .run file option.
  4. Download the .run file (currently this one). Make sure not to put it in /tmp.
  5. Make the .run file executable: chmod a+x cuda_7.5.18_linux.run.
  6. Become root.
  7. Execute the .run file: Pretend to accept their silly shrink-wrap license; say "yes" to installing just the NVIDIA kernel driver, and say "no" to everything else.

The installation should tell you it expects to have installed the NVIDIA kernel driver, but that you should reboot before continuing/retrying the toolkit installation. So...

  1. Having apparently succeeded, reboot.

Installing CUDA itself

  1. Be root.
  2. Locate and execute cuda_7.5.18_linux.run
  3. This time around, say No to installing the driver, but Yes to installing everything else, and accept the default paths (or change them, whatever works for you).

The installer is likely to now fail. That is a good thing assuming it's the kind of failure we expect: It should tell you your compiler version is not supported - CUDA 7.0 or 7.5 supports up to gcc 4.9 and you have some 5.x version by default. Now, if you get a message about missing libraries, that means my instructions above regarding prerequisites somehow failed, and you should comment here so I can fix them. Assuming you got the "good failure", proceed to:

  1. Re-invoke the .run file, this time with the --override option.
  2. Make the same choices as in step 11.

CUDA should now be installed, by default under /usr/local/cuda (that's a symlink). But we're not done!

Directing NVIDIA's nvcc compiler to use the right g++ version

NVIDIA's CUDA compiler actually calls g++ as part of the linking process and/or to compile actual C++ rather than .cu files. I think. Anyway, it defaults to running whatever's in your path as g++; but if you place another g++ under /usr/local/cuda/bin, it will use that first! So...

  1. Execute symlink /usr/bin/g++-4.9 /usr/local/cuda/bin/g++ (and for good measure, maybe also symlink /usr/bin/gcc-4.9 /usr/local/cuda/bin/gcc.

That's it.

Trying out the installation

  1. cd /root/NVIDIA_CUDA-7.5_Samples/0_Simple/vectorAdd
  2. make

The build should conclude successfully, and when you do

  1. ./vectorAdd

you should get the following output:

root@mymachine:~/NVIDIA_CUDA-7.5_Samples/0_Simple/vectorAdd# ./vectorAdd
[Vector addition of 50000 elements]
Copy input data from the host memory to the CUDA device
CUDA kernel launch with 196 blocks of 256 threads
Copy output data from the CUDA device to the host memory
Test PASSED
Done

Notes

  • You don't need to install the NVIDIA GDK (GPU Development Kit), but it doesn't hurt and it might be useful for some. Install it to the root directory of your system; it's pretty safe and there's an uninstaller afterwards: /usr/bin/uninstall_gdk.pl. In CUDA 8 it's already integrated into CUDA itself IIANM.
  • Do not install additional packages with names like nvidia-... or cuda... ; they might not hurt but they'll certainly not help.
  • Before doing any of these things, you might want to make sure your GPU is recognized at all, using lspci | grep -i nvidia.
  • ... well, almost all of this: You can't install the kernel driver if you're not root, of course. But you can build (not run) CUDA code without it. – einpoklum Apr 9 '16 at 13:11
  • Just tried this. the cuda installer just refuses to install. It bails out with a warning that you should use the .deb file. – user50037 Apr 16 '16 at 15:39
  • @WernerVanBelle: Can you post that as a separate question? Or at least quote the warning if it's too short? Also, IIRC it has some "force" command-line option, have you tried that? – einpoklum Apr 16 '16 at 15:57
  • All of this - except the driver installation - can also be done as a non-root user in your home directory, But that would only be enough to build CUDA code, not to run it. You need an appropriate nVIDIA driver in your kernel for that, and only a root user can make that happen. Sorry for my earlier comment which suggested otherwise. Also, to build as a non-root user, you might need to build your own version of gcc/g++ if your distribution only has a newer version (for CUDA 7.x you would need gcc 4.9.3). – einpoklum Feb 20 '17 at 21:51
  • @celavek: if you think this answer does not cover Debian 9 well enough, please explain why before you make a suggested edit. – einpoklum Oct 25 '17 at 10:55

I think you should do it using backports, I'm actually smoothly installing nvidia-cuda-toolkit 7.5 on debian jessie.

Add backports, non free, to your /etc/apt/sources.list. For me (on jessie) I just put this on the bottom of my file:

# jessie-backports
deb http://httpredir.debian.org/debian jessie-backports main contrib non-free

saved, apt-get update, and finally:

apt-get install -t jessie-backports nvidia-cuda-toolkit

After adding contrib and non-free repos to sources.list and running apt-get update, CUDA Toolkit is in Synaptic under nvidia-cuda-toolkit.

Try to use Network Installers for Ubuntu from this page:

https://developer.nvidia.com/cuda-downloads#linux

Installers for Ubuntu 14.* should be enough compatible.

  • 1
    I should have mentioned that the ubuntu installer did not work - updated the post to reflect this. – Greg Jul 24 '15 at 13:57
  • @Greg, have you figured out how to install Cuda on Debian eventually? – nullgeppetto Sep 3 '15 at 12:44
  • @nullgeppetto I ended up giving up on the idea of Debian as I found too many compatibility issues I was unable to overcome. – Greg Sep 5 '15 at 7:53
  • @Greg, hmmm, that's what I was afraid of.. So, did you go for *ubuntu or something else? Personally, I am still waiting for my gtx 960, so I will give it a try on Debian... I'll let you know if you want. – nullgeppetto Sep 5 '15 at 8:23

With Debian 9 "stretch" with an older GPU (GT 720) additional steps are needed. I see someone above (@celavek) had this, so I'll fill in what worked for me. The accepted answer covers almost everything needed. Recognizing this is a pretty niche example, but hopefully there may be some useful things in here that will save folks a few google searches.

For CUDA 8.0 in step 1 click "Legacy Releases" and select "CUDA Toolkit 8.0 GA 2". Then Linux, x86_64, Ubuntu, 16.04, runfile (local).

I did not accept the packaged driver and instead used my previously installed 384.130 drivers for my GPU. More info on that here: Debian Wiki. Your mileage may vary, I cannot speak for cards other than a GT 720. This was the path I chose, I have no regrets (yet).

When the installation fails due to an inability to local InstallUtils.pm in step 12 you will need to unpack the cuda_8.0.61_375.26_linux.run file but running it with the --tar mxvf flag. Then (as root) copy InstallUtils.pm to /usr/lib/x86_64-linux-gnu/pearl-base:

./cuda_8.0.61_375.26_linux.run --tar mxvf
sudo cp InstallUtils.pm /usr/lib/x86_64-linux-gnu/perl-base

Now step 12 command should succeed.

Your Debian 9.0 comes with g++ version 6+, this won't do. The compilation of vectorAdd in step 15 will fail. I followed this whitepaper: Installing Multiple Versions of GCC to install version 5.5.0. For 5.5.0 you will want this file

wget http://mirrors.concertpass.com/gcc/releases/gcc-5.5.0/gcc-5.5.0.tar.xz

and unpack the tarball with this:

tar -xJf gcc-5.5.0.tar.xz

I needed to update some things (libraries and add 32-bit compilation) for this to work for me:

sudo apt-get install libgmp3-dev libmpfr-dev libmpc-dev
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install build-essential gcc-multilib rpm libstdc++6:i386 libgcc1:i386 zlib1g:i386 libncurses5:i386

Now you can configure, make and install the compiler.

Remember to configure with the --prefix=/usr/local/gcc/5.5.0 flag

Now you can compile the vectorAdd example in step 15 with this:

make HOST_COMPILER=/usr/local/gcc/5.5.0/bin/g++

Or this:

export HOST_COMPILER=/usr/local/gcc/5.5.0/bin/g++
make

There is no need to modify the Makefile, it handles the compiler override correctly.

You should now have a working CUDA 8.0 installation on stretch.

Verifying install on Debian 9 Stretch & changing PATH & LD_LIBRARY_PATH

Einpoklum's answer above helped me install CUDA 10.0 on Debian 9 Stretch.

After successfully installing CUDA I could not verify the version, and troubleshot that it was because I needed to change the PATH & LD_LIBRARY_PATH permanently by editing the .bashrc file


CUDA Toolkit Documentation here

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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