This guide walks through the process of installing NVIDIA CUDA Toolkit and cuDNN on Ubuntu 24.04 for deep learning and GPU-accelerated applications.
- Ubuntu 24.04 LTS
- A compatible NVIDIA GPU
- Sufficient disk space (at least 5GB for CUDA and 1GB for cuDNN)
- Administrator (sudo) privileges
First, check if your system has a compatible NVIDIA GPU:
lspci | grep -i nvidia
- Add the NVIDIA driver repository:
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
- Install the NVIDIA driver (version 570):
sudo apt install libnvidia-common-570 nvidia-driver-570 libnvidia-gl-570
- Reboot your system to load the new driver:
sudo reboot
- Verify the driver installation after reboot:
nvidia-smi
You should see output showing your GPU and driver version 570.
- 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
- Install CUDA Toolkit 12.8:
sudo apt-get install cuda-toolkit-12-8
- 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
- Verify CUDA installation:
nvcc --version
You should see output indicating CUDA version 12.8.
- 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
- Install cuDNN for CUDA 12:
sudo apt-get -y install cudnn-cuda-12
- Reboot your system to finalize the installation:
sudo reboot
After reboot, verify that both CUDA and cuDNN are installed correctly:
- Check CUDA:
nvcc --version
- 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.
If you encounter missing library errors when running CUDA applications:
sudo apt install build-essential
sudo ldconfig
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.
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
Ensure your environment variables are set correctly:
echo $PATH | grep cuda
echo $LD_LIBRARY_PATH | grep cuda
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.