Install Nvidia Driver on Ubuntu 20.04

Install driver and CUDA

I don’t recommend installing the NVIDIA drivers that come with CUDA as they do not contain the dkms drivers that carry over into new kernel upgrades.

The Ubuntu repositories now contain the same drivers as the graphics-drivers PPA. So feel free to install the 495.44 drivers.

1
sudo apt install nvidia-driver-495

Reboot the system so the new driver takes effect.

Now, download the CUDA 11.5.0 .run file from NVIDIA:

1
wget https://developer.download.nvidia.com/compute/cuda/11.5.0/local_installers/cuda_11.5.0_495.29.05_linux.run

Run the .run file as sudo:

1
sudo sh ./cuda_11.5.0_495.29.05_linux.run

If you get the following, just choose Continue:

1
2
3
4
5
6
┌──────────────────────────────────────────────────────────────────────────────┐
│ Existing package manager installation of the driver found. It is strongly │
│ recommended that you remove this before continuing. │
│ Abort │
│ Continue │

Accept the EULA:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
┌──────────────────────────────────────────────────────────────────────────────┐
│ End User License Agreement │
│ -------------------------- │
│ │
│ NVIDIA Software License Agreement and CUDA Supplement to │
│ Software License Agreement. Last updated: October 8, 2021 │
│ │
│ The CUDA Toolkit End User License Agreement applies to the │
│ NVIDIA CUDA Toolkit, the NVIDIA CUDA Samples, the NVIDIA │
│ Display Driver, NVIDIA Nsight tools (Visual Studio Edition), │
│ and the associated documentation on CUDA APIs, programming │
│ model and development tools. If you do not agree with the │
│ terms and conditions of the license agreement, then do not │
│ download or use the software. │
│ │
│ Last updated: October 8, 2021. │
│ │
│ │
│ Preface │
│ ------- │
│ │
│──────────────────────────────────────────────────────────────────────────────│
│ Do you accept the above EULA? (accept/decline/quit): │
│ accept |

Unselect the video driver by pressing the spacebar while [X] Driver is highlighted:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
┌──────────────────────────────────────────────────────────────────────────────┐
│ CUDA Installer │
│ - [ ] Driver │
│ [ ] 495.29.05 │
│ + [X] CUDA Toolkit 11.5 │
│ [X] CUDA Samples 11.5 │
│ [X] CUDA Demo Suite 11.5 │
│ [X] CUDA Documentation 11.5 │
│ Options │
│ Install │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ Up/Down: Move | Left/Right: Expand | 'Enter': Select | 'A': Advanced options │

Then press the down arrow to Install. Press Enter then wait for installation to complete.

After the installation is complete add the following to the bottom of your ~/.profile or add it to the /etc/profile.d/cuda.sh file which you might have to create for all users (global):

1
2
3
4
5
# set PATH for cuda 11.5 installation
if [ -d "/usr/local/cuda-11.5/bin/" ]; then
export PATH=/usr/local/cuda-11.5/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.5/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
fi

Install libcudnn8

Add the Repo:

NOTE: The 20.04 repo from NVIDIA does not supply libcudnn but the 18.04 repo does and installs just fine into 20.04.

1
echo "deb http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 /" | sudo tee /etc/apt/sources.list.d/cuda_learn.list

Install the key:

1
sudo apt-key adv --fetch-keys  http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub

Update the system:

1
sudo apt update

Install libcudnn 8.0.4:

1
sudo apt install libcudnn8

I recommend now to reboot the system for the changes to take effect.

After it reboots check the installations using nvidia-smi and check CUDA install with nvcc --version and check libcudnn install:

1
2
3
4
5
6
7
8
~$ /sbin/ldconfig -N -v $(sed 's/:/ /' <<< $LD_LIBRARY_PATH) 2>/dev/null | grep libcudnn
libcudnn_cnn_infer.so.8 -> libcudnn_cnn_infer.so.8.0.4
libcudnn.so.8 -> libcudnn.so.8.0.4
libcudnn_adv_train.so.8 -> libcudnn_adv_train.so.8.0.4
libcudnn_ops_infer.so.8 -> libcudnn_ops_infer.so.8.0.4
libcudnn_cnn_train.so.8 -> libcudnn_cnn_train.so.8.0.4
libcudnn_adv_infer.so.8 -> libcudnn_adv_infer.so.8.0.4
libcudnn_ops_train.so.8 -> libcudnn_ops_train.so.8.0.4

Visit https://askubuntu.com/questions/1077061/how-do-i-install-nvidia-and-cuda-drivers-into-ubuntu/1077063#1077063 for detailed step on installing Nvidia driver on Ubuntu 18.04