Answer from xAI 😆
Here's a step-by-step guide to install CUDA 12.1 on Ubuntu 24.04:
1. Prerequisites
# Update system
sudo apt update && sudo apt upgrade -y
# Install build essentials and kernel headers
sudo apt install -y build-essential linux-headers-$(uname -r)
# Install required dependencies
sudo apt install -y wget software-properties-common gnupg2
2. Verify NVIDIA Driver Compatibility
CUDA 12.1 requires NVIDIA driver ≥ 525.60.13. First, check your GPU and install/update driver:
# Check your GPU
lspci | grep -i nvidia
# Add NVIDIA repository for latest drivers
wget
developer.download.nvidia.co…
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt update
# Install NVIDIA driver (525 or newer)
sudo apt install -y nvidia-driver-535 # or latest available ≥525
sudo reboot
Verify driver installation:
nvidia-smi
3. Install CUDA 12.1
# Add CUDA repository
wget
developer.download.nvidia.co…
sudo dpkg -i cuda-keyring_1.1-1_all.deb
# Update package list
sudo apt update
# Install CUDA 12.1 toolkit
sudo apt install -y cuda-toolkit-12-1
# Optional: Install full CUDA package (includes samples, etc.)
# sudo apt install -y cuda-12-1
4. Configure Environment
Add CUDA to your PATH. Edit ~/.bashrc:
echo 'export PATH=/usr/local/cuda-12.1/bin${PATH: :${PATH}}' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-12.1/lib64${LD_LIBRARY_PATH: :${LD_LIBRARY_PATH}}' >> ~/.bashrc
source ~/.bashrc
5. Verify Installation
# Check CUDA version
nvcc --version
# Compile and run CUDA sample
sudo apt install -y cuda-samples-12-1
cd /usr/local/cuda-12.1/samples/1_Utilities/deviceQuery
make
./deviceQuery
Expected output should show:
CUDA Version: 12.1
Device 0: "Your GPU Name"
Result = PASS
6. (Optional) Install cuDNN
For deep learning frameworks:
# Download cuDNN for CUDA 12.1 from NVIDIA Developer site (requires login)
# Then install:
sudo dpkg -i libcudnn8_8.x.x-1 cuda12.1_amd64.deb
sudo dpkg -i libcudnn8-dev_8.x.x-1 cuda12.1_amd64.deb
Troubleshooting
Driver conflicts: Purge old drivers with sudo apt purge nvidia*
Secure Boot: Disable in BIOS if kernel module fails to load
Missing kernel headers: sudo apt install linux-headers-$(uname -r)
PATH not found: Reboot or source ~/.bashrc
Compatibility Note
Ubuntu 24.04 is officially supported by CUDA 12.1. If you encounter issues, consider using the official NVIDIA CUDA repository method above, which handles dependencies automatically.
Your installation is complete when nvcc --version shows release 12.1 and deviceQuery passes!