Setting up TensorRT Environment on Ubuntu 22.04 / 20.04
Summary
Ubuntu 22.04 or Ubuntu 20.04
NVIDIA driver version: 535 (535.129.03)
CUDA version: 12.1.1
cuDNN version: 8.9.7 for CUDA 12.X
TensorRT version: 8.6 GA
Installing CUDA
Follow the official instruction, download CUDA from here.
Select CUDA 12.4.0 (March 2024), and then execute the commands prompted by the instruction on the website.
Here's an example set of commands to run:
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin
sudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda-repo-ubuntu2204-12-4-local_12.4.0-550.54.14-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2204-12-4-local_12.4.0-550.54.14-1_amd64.deb
sudo cp /var/cuda-repo-ubuntu2204-12-4-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda-toolkit-12-4Select CUDA 12.2.2 (August 2023), and then execute the commands prompted by the instruction on the website.
Here's an example set of commands to run:
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/12.2.2/local_installers/cuda-repo-ubuntu2004-12-2-local_12.2.2-535.104.05-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2004-12-2-local_12.2.2-535.104.05-1_amd64.deb
sudo cp /var/cuda-repo-ubuntu2004-12-2-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt update
sudo apt install -y cudaAfter installation, add CUDA to ~/.bashrc:
To test cuda installation, run the following command. The system should be able to find nvcc.
Installing cuDNN
Follow the official instruction, download cuDNN here.

Select "cuDNN v9.3.0, for CUDA 12.x" with the .deb file option, and then execute the commands prompted by the instruction on the website.
Here's an example set of command to run:
Select "cuDNN v8.9.7 (December 5th, 2023), for CUDA 12.x" with the .deb file option, and then execute the commands prompted by the instruction on the website.
Here's an example set of command to run:
(might not need do the following)
Install the runtime library.
Install the developer library.
Install the code samples.
run the test program to see if success
https://forums.developer.nvidia.com/t/verify-cudnn-install-failed/167220/4
Installing TensorRT
There are two parts of TensorRT installation
TensorRT GA
Goto https://developer.nvidia.com/tensorrt
Download both the "TensorRT 10.3 GA for Linux x86_64 and CUDA 12.0 to 12.5 TAR Package" and the DEB package
Install the DEB package with Software Install.
Alternatively, do the following commands
We also need to link the libraries. Unpack the tar package:
Then. move the unpacked directory to the installation path (~/Documents/), and add to bashrc
Install to Python using the following command
For TensorRT < 10.3, it might also need this dependency
TensorRT OSS
Seems that normally we don't need this thing.
For python:
Other Dependencies
Final Step
Follow this repo to use TRT
FAQ
solution:
the key is not installed. run the command in "Installing TensorRT" again
Last updated