Install CUDA Toolkit on Ubuntu 24.04 and 26.04

Step-by-step guide to installing NVIDIA CUDA Toolkit 12.8 via official APT repos on Ubuntu 24.04/26.04: driver-first workflow, 3.9 GB download

Table of contents
  1. 1.Introduction and Key Findings
  2. 2.Core Specifications and Comparison
  3. 3.Deep Dive and Operational Details
  4. 3.1.1. Repository Setup and Driver Pre-installation
  5. 3.2.2. Toolkit Installation and Disk Pressure
  6. 3.3.3. Inference-Only vs. Compile-Required Decision Fork
  7. 4.Scenario-Based Selection and Pitfall Checklist
  8. 5.FAQ
  9. 6.Sources & References
Install CUDA Toolkit on Ubuntu 24.04 and 26.04

Introduction and Key Findings

Recent validation on fresh Ubuntu 24.04 and 26.04 server images confirms the standardized deployment path for the CUDA Toolkit. Ubuntu’s official repositories do not provide a cuda-toolkit package in 24.04, while 26.04 only includes legacy versions; the NVIDIA official APT repository is mandatory. Testing on 24.04.5 and 26.04.1 shows the full toolchain pulls 138 packages, downloads 3918 MB of archives, and consumes 7543 MB on disk. The driver version is locked to 595.99.02, and a Tesla T4 (compute capability 7.5) reports Result = PASS. The core logic is driver first, toolkit second — the two are released independently. Running inference workloads (e.g., Ollama) requires only the driver plus pre-built wheels; compiling custom kernels or llama.cpp demands the full toolkit. This guide targets operators and developers deploying GPU compute in production, delivering reproducible minimal steps and pitfall avoidance.

Core Specifications and Comparison

Dimension Ubuntu 24.04 (Noble) Ubuntu 26.04 Key Note
Official repo cuda-toolkit availability None Legacy only Must enable NVIDIA official repo
Full toolkit install size (NVIDIA repo) 138 pkgs, 3918 MB download, 7543 MB disk Same scale (tested 26.04.1) Reserve ≥ 10 GB root space
Driver version (tested lock) 595.99.02 595.99.02 Toolkit metapackage does not depend on driver; install driver manually first
Verified GPU / compute capability Tesla T4 / CC 7.5 Tesla T4 / CC 7.5 Confirm with nvidia-smi and nvcc --version
Common mistake apt install cuda-toolkit fails directly Same Mixing driver/toolkit order causes dependency hell

Deep Dive and Operational Details

1. Repository Setup and Driver Pre-installation

Ubuntu’s multiverse repository ships outdated and incomplete CUDA snapshots; production environments should exclusively use the NVIDIA official repository. Execution sequence:

# 1. Fetch and install NVIDIA repo key and source (example for 24.04)
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 update

# 2. Install driver FIRST (toolkit metapackage does not pull driver)
sudo apt install -y nvidia-driver-595 # version matches tested 595.99.02
# Reboot to activate kernel modules
sudo reboot

Boundary condition: A reboot is mandatory after driver installation; otherwise subsequent nvcc-compiled binaries cannot communicate with the kernel module. If the server already installed drivers via ubuntu-drivers autoinstall, run apt purge nvidia-* first, then reinstall the pinned version above to prevent version drift.

2. Toolkit Installation and Disk Pressure

With the driver ready, launch the full toolkit in a single command:

sudo apt install -y cuda-toolkit-12-8 # metapackage name includes version; pulls 138 sub-packages

Tested download: 3918 MB, disk footprint: 7543 MB. Root partition free space ≥ 10 GB is strongly recommended. Post-install:

# Persist environment variables (optional: write to /etc/profile.d/cuda.sh)
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}}

# Verify
nvcc --version # Should show Cuda compilation tools, release 12.8
nvidia-smi # Driver Version: 595.99.02 and GPU detected

Limitation: Toolkit installation does not trigger kernel module rebuilds; DKMS runs only during the driver package phase. After a kernel upgrade, run dkms autoinstall manually.

3. Inference-Only vs. Compile-Required Decision Fork

  • Run models only (Ollama, pre-built wheels): sudo apt install -y nvidia-driver-595 is sufficient. Do not install cuda-toolkit — saves 7.5 GB disk and 138 packages of maintenance overhead.
  • Compile custom CUDA kernels / llama.cpp -DGGML_CUDA=ON / run CUDA Samples: Full toolkit is mandatory. The two paths are mutually exclusive in practice; mixing them causes header/runtime library version mismatches, manifesting as undefined symbol or CUDA driver version is insufficient.

Scenario-Based Selection and Pitfall Checklist

  1. Production inference node (model serving only): Install driver 595.99.02 + pre-built wheels only. Ban cuda-toolkit to reduce attack surface and disk usage.
  2. Development / compile node: Full toolkit install. Reserve ≥ 10 GB root. Configure /etc/apt/preferences.d/cuda to pin cuda-toolkit-12-8 and prevent rolling upgrades from breaking ABI.
  3. GPU invisible after kernel upgrade: Run dkms status to confirm nvidia/595.99.02 built for the new kernel; if missing, dkms install nvidia/595.99.02 -k $(uname -r).
  4. Pitfall: apt install cuda equals toolkit only, not driver+toolkit — NVIDIA documentation explicitly states the metapackage has no driver dependency. Do not expect a single command to handle both.
  5. Pitfall: Ubuntu 26.04 official repo legacy CUDA co-existing with NVIDIA repo new CUDA confuses nvcc priority — Explicitly Pin-Priority: -1 the nvidia-cuda-* packages from universe/multiverse in /etc/apt/preferences.

FAQ

Why does apt install cuda-toolkit fail directly on Ubuntu 24.04?

Because Noble (24.04) universe/multiverse repositories do not contain a package named cuda-toolkit at all. You must first add the NVIDIA official APT repository (cuda-keyring), then install the versioned metapackage such as cuda-toolkit-12-8.

Must I install the 7.5 GB full CUDA Toolkit just to run Ollama inference?

No. The source material explicitly states that only driver 595.99.02 plus pre-built wheels are required. The toolkit is only necessary when compiling CUDA C++, custom kernels, or llama.cpp.

After a kernel upgrade, nvidia-smi reports “Failed to initialize NVML: Driver/library version mismatch”. What now?

The driver kernel module was not rebuilt for the new kernel. Execute dkms install nvidia/595.99.02 -k $(uname -r) and reboot. If DKMS did not trigger automatically, verify /var/lib/dkms/nvidia/595.99.02/source exists and build manually.

Sources & References

Spotted outdated pricing, stock, or expired coupons?See methodology & report an update →

Related articles