Website Vidya
Linux & ServersStep-by-Step Guide

How to Install NVIDIA CUDA Toolkit on Ubuntu 24.04

Step-by-step guide to install NVIDIA CUDA Toolkit on Ubuntu 24.04 LTS with proprietary NVIDIA drivers, environment setup, and CUDA compiler verification.

RR
Rajesh RayLead Systems Educator
Published:
6 min read
PDF Cheat Sheet
How to Install NVIDIA CUDA Toolkit on Ubuntu 24.04
AI Executive SummaryWebsiteVidya AI

6 min read

Step-by-step guide to install NVIDIA CUDA Toolkit on Ubuntu 24.04 LTS with proprietary NVIDIA drivers, environment setup, and CUDA compiler verification.

Key Highlights
  • Prerequisites and Supported Releases
  • Step 1: Verifying CUDA-Capable GPU Hardware and Prerequisites
  • Step 2: Installing Essential Build Tools and Kernel Headers
Grounded in full engineering runbookWebsiteVidya AI Engine

Accelerating deep learning training, LLM inference with Ollama or vLLM, and computer vision pipelines requires direct access to high-performance GPU hardware acceleration. When you install nvidia cuda toolkit on ubuntu 24.04, you deploy the complete NVIDIA compiler toolchain (nvcc), GPU-accelerated math libraries (cuBLAS, cuFFT, cuDNN), and debugging utilities required to execute parallel workloads.

Ubuntu 24.04 LTS features Linux Kernel 6.8 and updated GCC 13/14 toolchains. Because modern CUDA releases require strict driver and kernel ABI compatibility, configuring the official NVIDIA CUDA network repository guarantees that your system receives synchronized kernel module updates, proprietary display drivers, and matched runtime libraries without dependency breakage.

This tutorial guides you through verifying GPU architecture compatibility, disabling the conflicting open-source Nouveau driver, installing matched proprietary NVIDIA drivers, registering official NVIDIA cryptographic repository keyrings in /etc/apt/keyrings/, configuring $PATH environment variables, and building a sample CUDA binary to verify end-to-end functionality.

Advertisement

Prerequisites and Supported Releases

This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat). The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.

Before proceeding, ensure you have the following requirements satisfied:

  • A workstation or server with a CUDA-capable NVIDIA GPU (GeForce, RTX, Quadro, Tesla, or A100/H100).
  • Ubuntu 24.04 LTS installed with active sudo administrative privileges.
  • GCC compiler, Make, and Linux kernel header development packages installed.
  • A stable broadband Internet connection for downloading proprietary drivers and packages.

Step 1: Verifying CUDA-Capable GPU Hardware and Prerequisites

Before attempting to install CUDA software, verify that your computer contains an authentic NVIDIA graphics processing unit. The lspci command interrogates the PCI bus and lists all connected display controllers.

Execute the following command in your terminal to inspect your GPU model and verify system architecture.

Advertisement
# Interrogate PCI bus for NVIDIA GPU hardware
lspci | grep -i nvidia

# Verify system architecture (x86_64 or aarch64)
uname -m

Step 2: Installing Essential Build Tools and Kernel Headers

Building NVIDIA proprietary kernel modules (via Dynamic Kernel Module Support or DKMS) requires the standard GNU C compiler toolchain and the exact kernel header packages matching your active Linux kernel.

Install build-essential, dkms, and the appropriate kernel development packages using APT.

# Update package metadata
sudo apt update

# Install build toolchain, dkms, and kernel headers
sudo apt install -y build-essential dkms linux-headers-$(uname -r)

Step 3: Disabling Conflicting Nouveau Open-Source Drivers

Ubuntu includes the open-source Nouveau kernel driver by default. However, Nouveau lacks support for CUDA parallel compute tasks and will conflict with proprietary NVIDIA drivers if loaded simultaneously.

Create a blacklist configuration file under /etc/modprobe.d/blacklist-nouveau.conf to prevent Nouveau from initializing during boot, and regenerate the initial RAM filesystem (initramfs).

Advertisement
# Blacklist the open-source Nouveau driver
sudo tee /etc/modprobe.d/blacklist-nouveau.conf << 'EOF'
blacklist nouveau
options nouveau modeset=0
EOF

# Regenerate initial RAM filesystem to apply kernel blacklisting
sudo update-initramfs -u

Step 4: Configuring Official NVIDIA CUDA Network Repository

While Ubuntu's default multiverse repository provides older CUDA toolkit builds, utilizing NVIDIA's official Debian repository ensures immediate access to the latest CUDA releases (such as CUDA 12.4, 12.5, or 12.6) optimized for Ubuntu 24.04.

First, download and install the official NVIDIA repository pin file to ensure high APT priority, followed by the repository keyring package.

# Download the repository pin configuration
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/cuda-ubuntu2404.pin
sudo mv cuda-ubuntu2404.pin /etc/apt/preferences.d/cuda-repository-pin-600

# Download and install the official NVIDIA keyring deb package
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
rm -f cuda-keyring_1.1-1_all.deb

Step 5: Installing NVIDIA Proprietary Drivers and CUDA Toolkit

Once the repository keyring is registered, refresh your APT package database. You can now install the complete CUDA toolkit package (cuda-toolkit-12-6 or meta-package cuda).

Installing cuda automatically pulls the matched proprietary NVIDIA display driver, DKMS kernel modules, and the complete CUDA compiler toolkit.

# Update package database to recognize NVIDIA repository
sudo apt update

# Install CUDA toolkit and matched proprietary driver stack
sudo apt install -y cuda-toolkit-12-6

# Reboot system to unload Nouveau and initialize NVIDIA kernel modules
sudo reboot

Step 6: Verifying Driver Initialization with nvidia-smi

After rebooting, verify that the NVIDIA kernel driver is running and communicating properly with your physical GPU hardware by running the NVIDIA System Management Interface utility (nvidia-smi).

The output displays your GPU model, driver version, VRAM utilization, power usage, and the maximum supported CUDA version.

# Inspect active GPU hardware and driver status
nvidia-smi

Step 7: Configuring CUDA Environment Variables

To allow your shell to find the nvcc compiler and dynamically link CUDA runtime libraries, you must add the CUDA binary path to your $PATH and library directory to $LD_LIBRARY_PATH.

You can configure these variables system-wide by creating a script under /etc/profile.d/cuda.sh, and for your current user account by appending them to ~/.bashrc.

# Add CUDA environment variables system-wide
sudo tee /etc/profile.d/cuda.sh << 'EOF'
export PATH=/usr/local/cuda/bin${PATH:+:$PATH}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
export CUDA_HOME=/usr/local/cuda
EOF

# Make the profile script executable
sudo chmod +x /etc/profile.d/cuda.sh

# Source the new profile script in current shell
source /etc/profile.d/cuda.sh

Step 8: Verifying nvcc Compiler and Building a Sample Program

Test your CUDA installation by checking the compiler version with nvcc --version. Then, write and compile a minimal CUDA C++ program to confirm that kernel execution on the GPU succeeds.

Create a test file test_cuda.cu, compile it with nvcc, and execute the resulting binary.

# Verify the CUDA compiler version
nvcc --version

# Create a simple CUDA verification source file
cat << 'EOF' > test_cuda.cu
#include <iostream>

__global__ void helloFromGPU() {
    printf("Hello from GPU thread %d!\n", threadIdx.x);
}

int main() {
    std::cout << "Launching CUDA kernel..." << std::endl;
    helloFromGPU<<<1, 4>>>();
    cudaDeviceSynchronize();
    std::cout << "CUDA kernel execution finished successfully!" << std::endl;
    return 0;
}
EOF

# Compile the CUDA program
nvcc test_cuda.cu -o test_cuda

# Run the compiled binary
./test_cuda

Troubleshooting and Common Errors

When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:

Command 'nvcc' not found after installing CUDA toolkit

Resolution: The toolkit installs into /usr/local/cuda/bin. Ensure you added /usr/local/cuda/bin to your $PATH environment variable in ~/.bashrc or /etc/profile.d/cuda.sh and ran source ~/.bashrc.

nvidia-smi reports: 'NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver'

Resolution: This typically occurs when Secure Boot is active in UEFI without enrolling the MOK (Machine Owner Key) generated during driver installation. Either disable Secure Boot in UEFI firmware or enroll your MOK key using sudo mokutil --import /var/lib/shim-signed/mok/MOK.der and reboot.

DKMS kernel module build fails during apt upgrade

Resolution: Verify that linux-headers-$(uname -r) is installed. If you recently updated the kernel, ensure you booted into the latest kernel before compiling DKMS modules with sudo dkms autoinstall.

Security Best Practices and Hardening

Download CUDA keyrings and repositories exclusively from official HTTPS domains (developer.download.nvidia.com).

Enroll MOK keys securely when using UEFI Secure Boot to prevent unsigned or malicious kernel modules from loading.

Avoid running arbitrary CUDA sample executables or compiled machine learning models under the root superuser account.

Regularly review /etc/apt/sources.list.d/cuda*.list to verify that repository signatures remain strictly pinned and up to date.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

3 FAQs
Yes. CUDA toolkits install into versioned directories like /usr/local/cuda-12.4 and /usr/local/cuda-12.6. The /usr/local/cuda symbolic link points to the active version, switchable at any time.
If you install the full cuda package, it includes compatible display drivers. If you already have working NVIDIA drivers installed via ubuntu-drivers, you can install only cuda-toolkit-12-6 to avoid driver reinstallation.
Install the NVIDIA Container Toolkit (nvidia-container-toolkit) and configure the Docker daemon to enable the --gpus all flag.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout