Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MarcoDotIO/67122aa82f1ab72a618fa456f9959305 to your computer and use it in GitHub Desktop.
Save MarcoDotIO/67122aa82f1ab72a618fa456f9959305 to your computer and use it in GitHub Desktop.

Installing CUDA and cuDNN on Ubuntu 24.04

This guide walks through the process of installing NVIDIA CUDA Toolkit and cuDNN on Ubuntu 24.04 for deep learning and GPU-accelerated applications.

Prerequisites

  • Ubuntu 24.04 LTS
  • A compatible NVIDIA GPU
  • Sufficient disk space (at least 5GB for CUDA and 1GB for cuDNN)
  • Administrator (sudo) privileges

Step 1: Verify Your GPU

First, check if your system has a compatible NVIDIA GPU:

lspci | grep -i nvidia

Step 2: Install NVIDIA GPU Drivers

  1. Add the NVIDIA driver repository:
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
  1. Install the NVIDIA driver (version 570):
sudo apt install libnvidia-common-570 nvidia-driver-570 libnvidia-gl-570
  1. Reboot your system to load the new driver:
sudo reboot
  1. Verify the driver installation after reboot:
nvidia-smi

You should see output showing your GPU and driver version 570.

Step 3: Install CUDA Toolkit 12.8

  1. Download and install the CUDA repository keyring:
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
  1. Install CUDA Toolkit 12.8:
sudo apt-get install cuda-toolkit-12-8
  1. Add CUDA to your PATH by adding these lines to your ~/.bashrc file:
echo 'export PATH=/usr/local/cuda-12.8/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-12.8/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
  1. Verify CUDA installation:
nvcc --version

You should see output indicating CUDA version 12.8.

Step 4: Install cuDNN 9.8.0

  1. Follow these installation instructions to install cuDNN:
wget https://developer.download.nvidia.com/compute/cudnn/9.8.0/local_installers/cudnn-local-repo-ubuntu2404-9.8.0_1.0-1_amd64.deb
sudo dpkg -i cudnn-local-repo-ubuntu2404-9.8.0_1.0-1_amd64.deb
sudo cp /var/cudnn-local-repo-ubuntu2404-9.8.0/cudnn-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
  1. Install cuDNN for CUDA 12:
sudo apt-get -y install cudnn-cuda-12
  1. Reboot your system to finalize the installation:
sudo reboot

Step 5: Verify the Installation

After reboot, verify that both CUDA and cuDNN are installed correctly:

  1. Check CUDA:
nvcc --version
  1. Create a simple test program to verify cuDNN:
cat > cudnn_test.cpp << EOF
#include <cudnn.h>
#include <iostream>

int main() {
    cudnnHandle_t handle;
    cudnnCreate(&handle);
    
    size_t version = cudnnGetVersion();
    std::cout << "cuDNN version: " << version << std::endl;
    
    cudnnDestroy(handle);
    return 0;
}
EOF

nvcc -o cudnn_test cudnn_test.cpp -lcudnn
./cudnn_test

If this runs without errors and displays a cuDNN version, the installation is successful.

Common Issues and Troubleshooting

Missing Libraries

If you encounter missing library errors when running CUDA applications:

sudo apt install build-essential
sudo ldconfig

CUDA and Driver Version Mismatch

Ensure your NVIDIA driver is compatible with CUDA 12.8. If needed, install a specific driver version:

sudo apt install nvidia-driver-xxx

Where xxx is the compatible driver version.

Cannot Find cuDNN

If applications can't find cuDNN libraries, create symbolic links:

sudo ln -s /usr/lib/x86_64-linux-gnu/libcudnn.so.9 /usr/local/cuda-12.8/lib64/libcudnn.so

Verify Environment Variables

Ensure your environment variables are set correctly:

echo $PATH | grep cuda
echo $LD_LIBRARY_PATH | grep cuda

Resources


Note: This guide is specifically for Ubuntu 24.04 with CUDA 12.8 and cuDNN 9.8.0. If you're using different versions, the installation steps might vary.

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