How to Install CUDA 8 and cuDNN 5 on Debian-based Systems

TensorFlow 1.0 was announced today, so let us take a moment to review how to avoid the common pitfalls that arise during an installation CUDA 8 and cuDNN 5.

We assume that the reader intends to carry out the installation on a Debian-based system: Debian, Ubuntu, Linux Mint, and so on. We also assume that the reader has downloaded the .run version of the CUDA installer, as well as the .tgz file containing cuDNN.

1. Rebooting in Text Mode

First off, rebooting the machine in text mode (without the GUI) is helpful. This is to avoid conflicts with X Windows. Many tutorials online suggest various ways of killing X Windows, but it seems simpler to avoid the ordeal altogether by booting into text mode.

Open the terminal, and type

   sudo nano /etc/default/grub

to edit the GRUB configuration file. Change quiet in

   GRUB_CMDLINE_LINUX_DEFAULT="quiet"

to text, and remove the leading # from

   # GRUB_TERMINAL=console

to invoke console mode. Hit Ctrl+X and then Y to save and exit. Run

   sudo update-grub

to apply the updated settings.

Now, run

   systemctl get-default

and write down the output text somewhere. We will need this to revert to GUI boot once the installation process is over. Afterwards, run

   sudo systemctl enable multi-user.target --force
   sudo systemctl set-default multi-user.target

Rebooting the machine at this point will lead us to a command-line interface.

2. Installing CUDA

If Nvidia drivers installed via APT are present in the system, the CUDA installer will crash. We must first remove all traces of Nvida drivers by running

   sudo apt purge *nvidia*

A complete installation of Nvidia drivers require recommended libraries, without with the CUDA installer will print a warning message. Install the libraries by running

   sudo apt install libxmu-dev libxmu-headers libxmuu-dev libglu1-mesa-dev

Installation of CUDA requires a Perl 5 module, which comes packaged with the .run file. We must alert the system’s Perl 5 of this fact; we do so by running

   export PERL5LIB=.

in the directory that the .run file is in.

Now, it is likely that the version of gcc present in the system is higher than the intended version for the CUDA installer. As far as I can tell, newer compilers—I tested with gcc version 6.3.0 20170205 (Debian 6.3.0-6)—do not present any trouble, so long as we pass in the override command to the CUDA installer. We run the CUDA installer with the following command:

   ./cuda_installer_file_name.run --override

Here we assume that we are in the directory the .run file is in.

At this point, say yes to all the prompts, and the installation script shouldn’t give us any trouble.

3. Installing cuDNN

Here we assume that we have selected the default option of creating a symlink at

   /usr/local/cuda

Go to the directory that contains the cuDNN .tgz file, and run

   tar xzf cudnn_file_name.tgz

to unpack the files. The tarball yields two directories: include and lib64. Move all files in include into /usr/local/cuda/include, and move all files in lib64 into /usr/local/cuda/lib64.

We have now successfully installed CUDA and cuDNN.

4. Reverting to GUI mode

Now, we access the GRUB setting once again by running

   sudo nano /etc/default/grub

Change text in

   GRUB_CMDLINE_LINUX_DEFAULT="text"

to text, and append a leading # to

   GRUB_TERMINAL=console

Hit Ctrl+X and then Y to save and exit. Run

   sudo update-grub

to apply the updated settings.

Now, run

   sudo systemctl set-default DEFAULTTEXT

where DEFAULTTEXT is the text we wrote down in Section 1.

Rebooting the machine at this point will lead us to the familiar GUI.