Nvidia driver and cuda installation for ML and deep learning on Ubuntu

vahid_jani
4 min readJun 10, 2020

--

Recently I was busy installing NVIDIA driver and CUDA support on my new computer. It took me some hours in order to get it done using the official helps, so I want to share my experience here for others. Using this tutorial you will be able to install this in just 10 min …

First lets take a look at what we should do :

  1. Install NVIDIA driver
  2. Install CUDA toolkit
  3. Install cuDNN SDK

So lets do these steps:

  1. Install NVIDIA driver :

Option 1 : Using GUI on Ubuntu :

I propose the easiest way here . Search for “software updater” using window key in your keyboard. once you see the dialog box select the “settings”:

In settings go to “additional drivers” : You should see your NVIDIA Hardware there. Then select the first option “NVIDIA-driver-440 (proprietary,tested)”(in my case) and click “ Apply changes”. Then you need to restart your computer.

Option 2: Using Ubuntu Terminal

a. update the system

sudo apt update && sudo apt upgrade

b. check the system already has it installed or not :

lspci -v | less 

in the printed list look for the name that has [VGA controller] at the end. if it is nvidia so your machine is using that. other wise go on and install it

c. check the name of available NVIDIA-drivers for your machine.

ubuntu-drivers devices

d. Install the driver that is recommended in the list.

sudo apt install nvidia-driver-430

e. Reboot the system

sudo reboot 

Note: After installing the driver using option 1 or 2 and restarting the system check if it is installed:

nvidia-smi

2. Install CUDA toolkit:

option1. Install all at once

option1 : using apt repo (this method change the installation of gpu driver, after installation check nvidia-smi if it didnt work. install driver again and use option2 not this method.)

sudo apt install nvidia-cuda-toolkit

option2 : download and install manually from nvidia

select runfile(local) as Installertype in this url and then it will gives you two command line like below :

wget https://developer.download.nvidia.com/compute/cuda/11.2.2/local_installers/cuda_11.2.2_460.32.03_linux.run
sudo sh cuda_11.2.2_460.32.03_linux.run

during installation uncheck the driver installation because you have already install it and then select install option.

uncheck driver

and add paths to environmental vars :

sudo vim ~/.bashrc

go to the end of the file and add the bellow there(change cuda version with yours):

export PATH=/usr/local/cuda-11.2/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export CUDA_HOME=/usr/local/cuda

then use the below code to apply changes:

source ~/.bashrc

verify it by :

echo $PATH

b. After installing using option 1 or 2

check if it is OK by typing “nvcc --version" . you should get something like this:

3. Install cuDNN SDK:

option 1: Use package manager and install every thing automatically (available for Ubuntu)

You need to go to the NVIDIA website “ https://developer.nvidia.com/cudnn” , make a free account and log in. Then download cuDNN Runtime (deb) or cudnn Developr(deb) for your desired version and after downloading, install it using terminal:

 sudo dpkg -i <path_to_file.deb>

Note: remember to download the Debian file and you need only Runtime version if you don't want to develop something.

option 2: download cuDNN Library for linux:

these are compiled files-> download, unzip and add it to environmental vars

(description on https://medium.com/analytics-vidhya/install-cuda-11-2-cudnn-8-1-0-and-python-3-9-on-rtx3090-for-deep-learning-fcf96c95f7a1)

4. install Tensorflow or Pytorch

for the latest help go to official websites

sample Tensorflow or pytorch GPU using pip:

pip install tensorflowpip3 install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

--

--