How to install CUDA and cuDNN on Ubuntu 16.04 LTS

I've been running this machine for TensorFlow and Keras with Jupyter notebook.

These are my environments:

$ cat /etc/lsb-release

$ lspci | grep VGA
01:00.0 VGA compatible controller: NVIDIA Corporation GP104 [GeForce GTX 1080] (rev a1)

Disable secure boot on UEFI

First, we need to disable "secure boot" on UEFI menu because it prevents NVIDIA driver from loading into OS. So enter UEFI menu while boot time by pressing the key something like the delete key.

That's the first time I heard that. I used to use BIOS, but now, a lot of motherboards recently released use UEFI. And UEFI has secure boot (see detail here, this was helpful for me).

If you use an ASUS motherboard, this document also can be helpful.

Remove old NVIDIA driver and CUDA

$ dpkg -l | grep nvidia
$ dpkg -l | grep cuda
$ sudo apt-get --purge remove nvidia-*
$ sudo apt-get --purge remove cuda-*

Install new NVIDIA driver and CUDA9.0

Download CUDA Toolkit 9.0

Download from NVIDIA developer site.


$ sudo dpkg -i cuda-repo-ubuntu1604_9.0.176-1_amd64.deb
$ sudo apt-key adv --fetch-keys
$ sudo apt-get update
$ sudo apt-get install cuda



export PATH="/usr/local/cuda/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda/lib64:$LD_LIBRARY_PATH"

Then reboot.

sudo reboot

Check that the driver was installed

$ nvidia-smi

This command shows the status of the graphics card installed on your machine like this:

| NVIDIA-SMI 390.25                 Driver Version: 390.25                    |
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|   0  GeForce GTX 1080    Off  | 00000000:01:00.0  On |                  N/A |
| 27%   36C    P8    12W / 180W |   7753MiB /  8116MiB |      0%      Default |

| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|    0      1351      G   /usr/lib/xorg/Xorg                            24MiB |
|    0     12638      C   /home/jupyter/tensorflow/bin/python3        7717MiB |

Install cuDNN

Download cuDNN

Download Debian package from NVIDA developer site.

Install the rutime library

$ sudo dpkg -i libcudnn7_7.0.5.15-1+cuda9.0_amd64.deb

Install the developer library

$ sudo dpkg -i libcudnn7-dev_7.0.5.15-1+cuda9.0_amd64.deb



export CUDA_HOME=/usr/local/cuda-9.0

Check that the cuDNN works

$ cp -r /usr/src/cudnn_samples_v7/ $HOME
$ cd  $HOME/cudnn_samples_v7/mnistCUDNN
$ make clean && make
$ ./mnistCUDNN
Test passed!

Stop LightDM

LightDM start to run when you install CUDA. If you use Ubuntu server, it's not necessary to run.

Disable LigthDM

Rewrite GRUB_CMDLINE_LINUX like below:



Update and reboot.

sudo update-grub
sudo reboot