Skip to content

Instantly share code, notes, and snippets.

@denguir
Last active February 22, 2025 12:18
Show Gist options
  • Save denguir/b21aa66ae7fb1089655dd9de8351a202 to your computer and use it in GitHub Desktop.
Save denguir/b21aa66ae7fb1089655dd9de8351a202 to your computer and use it in GitHub Desktop.
Installation procedure for CUDA / cuDNN / TensorRT

How to install CUDA / cuDNN / TensorRT on Ubuntu

Install NVIDIA drivers

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 525, adapt to yours

sudo apt install nvidia-driver-525

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

Check CUDA install

nvcc --version

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 ./<filename.deb>
sudo cp /var/cudnn-<something>.gpg /usr/share/keyrings/

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

sudo apt update
sudo apt install libcudnn8
sudo apt install libcudnn8-dev
sudo apt install libcudnn8-samples

Test CUDA on Pytorch

Create a virtualenv and activate it

sudo apt-get install python3-pip
sudo pip3 install virtualenv 
virtualenv -p py3.10 venv
source venv/bin/activate

Install pytorch

pip3 install torch torchvision torchaudio

Open Python and execute a test

import torch
print(torch.cuda.is_available()) # should be True

t = torch.rand(10, 10).cuda()
print(t.device) # should be CUDA

Install TensorRT

Download tensorrt .deb file

Go to Nvidia webiste here. Select latest TensorRT version that matches your CUDA version and download the DEB file.

sudo apt install ./<filename.deb>
sudo apt update
sudo apt install tensorrt

Verify trtexec

Verify that the trtexec utility is present.

whereis trtexec # should be trtexec: /usr/src/tensorrt/bin/trtexec
/usr/src/tensorrt/bin/trtexec
@moussahmed
Copy link

I have the same problem @maifeeulasad . Can you help me ?

@Muthukamalan
Copy link

I'm using Pop OS, installed successfully, but after sometime. my screen got frozen , every time I went to tty mode and kill gnome session.

please suggest how to resolve. I'm new to linux community

cc: @denguir @maifeeulasad

@jt-z
Copy link

jt-z commented Sep 9, 2024

Thank you. I have successfully installed it on Linux 22.04 with a 3060GPU, following the official link for cuDNN installation cuDNN 9.4.0 Downloads | NVIDIA Developer.

@fordnox
Copy link

fordnox commented Oct 8, 2024

This worked for me for Ubuntu 24.04 and GeForce RTX 4060 Ti 16GB after trying multiple versions:

https://gist.github.com/fordnox/538b48ac956341728573786a80e08859

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment