Nvidia x Cuda x Linux Installation

1. Verify CUDA-Capable GPU:

lspci | grep -i nvidia

The output should be similar to the following:

00:1e.0 3D controller: NVIDIA Corporation TU104GL [Tesla T4] (rev a1)

2. Verify Supported Version of Linux

uname -m && cat /etc/*release

The output should be similar to the following:

x86_64
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=24.04
DISTRIB_CODENAME=noble
DISTRIB_DESCRIPTION=”Ubuntu 24.04.1 LTS”
PRETTY_NAME=”Ubuntu 24.04.1 LTS”
NAME=”Ubuntu”
VERSION_ID=”24.04”
VERSION=”24.04.1 LTS (Noble Numbat)”
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL=”https://www.ubuntu.com/"
SUPPORT_URL=”https://help.ubuntu.com/"
BUG_REPORT_URL=”https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL=”https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo

3. Verify the System Has gcc Installed

gcc --version

The output should be similar to the following:

gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0

4. Driver Installer

sudo apt-get install -y nvidia-open

5. CUDA Toolkit Installer

1
2
3
wget https://developer.download.nvidia.com/compute/cuda/12.8.0/local_installers/cuda_12.8.0_570.86.10_linux.run

sudo sh cuda_12.8.0_570.86.10_linux.run

The output looks like this, 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
┌──────────────────────────────────────────────────────────────────────────────┐
│ CUDA Installer │
│ - [ ] Driver │
│ [ ] 495.29.05 │
│ + [X] CUDA Toolkit 12.8 │
│ [X] CUDA Samples 12.8 │
│ [X] CUDA Demo Suite 12.8 │
│ [X] CUDA Documentation 12.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 12.8 installation
if [ -d "/usr/local/cuda-12.8/bin/" ]; then
export PATH=/usr/local/cuda-12.8/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-12.8/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
fi

6. Reboot the system

sudo reboot

7. Remove Outdated Signing Key: (Optional)

sudo apt-key del 7fa2af80

8. Update the Apt repository cache

sudo apt-get update

9. Install the cuDNN library

These are the installation instructions for Debian 11, Ubuntu 18.04, Ubuntu 20.04, 22.04, and 24.04 users.

Approach 1: Specific for ubuntu1804

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

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

sudo apt-get update
  1. Install the cuDNN library:
1
sudo apt install libcudnn8

Approach 2:

  1. Enable the repository:

Where ${OS} is debian11, ubuntu1804, ubuntu2004, ubuntu2204, or ubuntu2404.

1
2
3
4
5
6
7
8
9
wget https://developer.download.nvidia.com/compute/cuda/repos/${OS}/x86_64/cuda-${OS}.pin 

sudo mv cuda-${OS}.pin /etc/apt/preferences.d/cuda-repository-pin-600

sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/${OS}/x86_64/3bf863cc.pub

sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/${OS}/x86_64/ /"

sudo apt-get update
  1. Install the cuDNN library:
    1
    2
    sudo apt-get install libcudnn8=${cudnn_version}-1+${cuda_version}
    sudo apt-get install libcudnn8-dev=${cudnn_version}-1+${cuda_version}

Where:

  • ${cudnn_version} is 8.9.0.*
  • ${cuda_version} is cuda12.1 or cuda11.8

10. Reboot the system

sudo reboot

11. Verifying the Install on Linux

nvcc -V

The output should be similar to the following:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2025 NVIDIA Corporation
Built on Wed_Jan_15_19:20:09_PST_2025
Cuda compilation tools, release 12.8, V12.8.61
Build cuda_12.8.r12.8/compiler.35404655_0

References:

  1. https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#about-this-document
  2. https://docs.nvidia.com/deeplearning/cudnn/archives/cudnn-890/install-guide/index.html
  3. https://askubuntu.com/questions/1077061/how-do-i-install-nvidia-and-cuda-drivers-into-ubuntu
  4. cuda-installation.sh