How to install CUDA & cuDNN on Ubuntu

Install NVIDIA drivers

https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#ubuntu

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb

sudo dpkg -i cuda-keyring_1.1-1_all.deb

Important – sometimes Secure Boot in BIOS is conflicting nvidia drivers work, so you might want to switch off it before you proceed

Update & upgrade

sudo apt update && sudo apt upgrade

Remove previous NVIDIA installation

sudo apt autoremove nvidia* --purge

Check Ubuntu devices

ubuntu-drivers devices

You will install the NVIDIA driver whose version is tagged with recommended

Install Ubuntu drivers

sudo ubuntu-drivers autoinstall

Install NVIDIA drivers

My recommended version is 550, adapt to yours sudo apt install nvidia-driver-550

Reboot & Check

reboot

after restart verify that the following command works

nvidia-smi

Install CUDA drivers

Update & upgrade

sudo apt update && sudo apt upgrade

Install CUDA toolkit

sudo apt install nvidia-cuda-toolkit nvidia-gds

Install cuDNN

Download cuDNN .deb file

You can download cuDNN file here. You will need an Nvidia account.

Select the cuDNN version for the appropriate CUDA version, which is the version that appears when you run:

nvcc --version

Install cuDNN

sudo apt install ./cudnn-local-repo-ubuntu2204-8.9.7.29_1.0-1_amd64.deb

sudo cp /var/cudnn-<something>.gpg /usr/share/keyrings/

My cuDNN version is 9, adapt the following to your version:

sudo apt update sudo apt install libcudnn9 libcudnn9-dev libcudnn9-samples

Installation Instructions:
wget https://developer.download.nvidia.com/compute/cudnn/9.3.0/local_installers/cudnn-local-repo-ubuntu2204-9.3.0_1.0-1_amd64.debsudo dpkg -i cudnn-local-repo-ubuntu2204-9.3.0_1.0-1_amd64.debsudo cp /var/cudnn-local-repo-ubuntu2204-9.3.0/cudnn-*-keyring.gpg /usr/share/keyrings/sudo apt-get updatesudo apt-get -y install cudnn
To install for CUDA 11, perform the above configuration but install the CUDA 11 specific package:
sudo apt-get -y install cudnn-cuda-11
To install for CUDA 12, perform the above configuration but install the CUDA 12 specific package:
sudo apt-get -y install cudnn-cuda-12

Docker GPU support

sudo apt install -y nvidia-docker2
sudo systemctl daemon-reload
sudo systemctl restart docker

Remember current version of cude debs

sudo apt-mark hold nvidia-dkms-550
sudo apt-mark hold nvidia-driver-550
sudo apt-mark hold nvidia-utils-550