[Ubuntu] Installing nvidia driver, CUDA and cuDNN for Ubuntu

1 minute read

In this document, I post how to install nvidia driver, CUDA and cuDNN for ubuntu.


Prerequisites

Note: Make suer to check version compatibility bewteen drivers.

nvidia driver

You can install nvidia driver when you install CUDA. But If you want to install specific version of nvidia driver, download it from official website, or download it directly using wget. For example,

$ wget http://us.download.nvidia.com/XFree86/Linux-x86_64/418.56/NVIDIA-Linux-x86_64-418.56.run

CUDA

Download runfile from official website. I selected Linux-x86_64-Ubuntu-16.04-runfile (local). Or, you can also run following line.

$ wget https://developer.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda_10.1.168_418.67_linux.run

cuDNN

Download cuDNN from here. You need to have nvidia developer account to download it. Downdload cuDNN 1.Runtme, 2.Developer, and 3.Code Samples and User Guide for Ubuntu 16.04 (The last one is optional).


Installation

Step 1. nvidia driver

Note: Install dkms before installation (sudo apt-get install dkms). It prevents ubuntu from reinstalling nvidia-driver for every time you reboot.

  • Stop lightdm and enter into text login mode.
    $ sudo service stop lightdm
    $ sudo init 3
    
  • Install nvidia driver
    $ sudo sh NVIDIA-Linux-x86_64-418.56.run --dkms --no-opengl-files --no-x-check
    

    When there is problem installing driver (e.g. "You appear to be running an X server"), --no-x-check gives you detail error, such as "nvidia-uvm appears to already be loaded in your kernel".

  • And if there is such error, run following command.
    $ sudo stop nvidia-digits-server
    $ sudo service nvidia-docker stop
    $ sudo rmmod nvidia-uvm
    

Step 2. Install CUDA

  • Run following command, and select only CUDA toolkit.
    $ sudo sh cuda_10.1.168_418.56.run
    

Step 3. Install cuDNN

  • Install runtime, developer, code samples and the cuDNN library User Guide (optional) with following lines.
    $ sudo dpkg -i libcudnn7_7.6.0.64-1+cuda10.1_amd64.deb
    $ sudo dpkg -i libcudnn7-dev_7.6.0.64-1+cuda10.1_amd64.deb
    $ sudo dpkg -i libcudnn7-doc_7.6.0.64-1+cuda10.1_amd64.deb
    

Step 4. Add path to your .zshrc or .bashrc

$ vim ~/.zshrc

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

References

cuDNN installation guide
nvidi-uvm error


Leave a Comment