GPU-accelerated computing powers machine learning training, scientific simulations, video encoding, and real-time data analysis. NVIDIA’s CUDA Toolkit provides the compiler, libraries, and debugging tools needed to build these applications on NVIDIA GPUs. Unlike OpenCL (cross-platform but less optimized) or AMD’s ROCm (AMD-only), CUDA integrates deeply with NVIDIA hardware architectures from Turing through Blackwell, delivering peak performance for supported workloads.
This guide walks through installing the CUDA Toolkit on Ubuntu using NVIDIA’s official APT repository. By the end, you will have a complete CUDA development environment with access to the nvcc compiler, cuBLAS, cuFFT, and cuRAND libraries, plus profiling tools like Nsight Compute. The instructions cover Ubuntu 24.04 LTS and 22.04 LTS, which are the currently supported releases for CUDA development.
Check GPU Compatibility Before Installation
First, before installing CUDA, verify that your system has an NVIDIA GPU with compute capability 5.0 or higher. Specifically, CUDA 12.x and 13.x require Maxwell architecture or newer (GTX 750 Ti and later). Run the following command to identify your GPU:
lspci | grep -i nvidia
You should see output similar to:
01:00.0 VGA compatible controller: NVIDIA Corporation GA106 [GeForce RTX 3060 Lite Hash Rate] (rev a1)
If the command returns no output, your system either lacks an NVIDIA GPU or the hardware is not detected. Check your BIOS settings and ensure the GPU is properly seated before proceeding.
Remove Existing CUDA and NVIDIA Installations
Skip this section if you have a fresh system without prior NVIDIA or CUDA installations. However, if you already have existing NVIDIA drivers on Ubuntu or CUDA packages, remove them first to prevent conflicts and installation failures.
Remove NVIDIA Packages Installed via APT
If you installed NVIDIA drivers or CUDA using the APT package manager, the following command removes all related packages cleanly. The quoted wildcard patterns prevent shell expansion and allow APT to match packages precisely:
sudo apt remove --purge "*cuda*" "*cublas*" "*cufft*" "*cufile*" "*curand*" "*cusolver*" "*cusparse*" "*gds-tools*" "*npp*" "*nvjpeg*" "nsight*" "*nvvm*" "*nvidia*"
Next, after removing the packages, clean up orphaned dependencies:
sudo apt autoremove --purge
Notably, the --purge flag removes configuration files along with the packages, ensuring a clean uninstallation.
Remove NVIDIA Drivers Installed via Runfile
If you installed NVIDIA drivers using a runfile, the uninstallation process differs from APT-based installations. Before running the uninstaller, switch to a text console (TTY), sign in, and stop the display manager:
sudo systemctl stop gdm3
Next, run the NVIDIA uninstaller:
sudo /usr/bin/nvidia-uninstall
Finally, after removal completes, reboot or restart the display manager. This script removes driver components installed through the runfile method without affecting system package management.
Never mix installation methods. Using APT removal commands on runfile installations (or vice versa) creates incomplete removals and conflicts that are difficult to resolve.
Remove CUDA Toolkit Installed via Runfile
If you installed the CUDA Toolkit using a runfile instead of the APT repository, remove it using the included uninstaller script. Replace X.Y with your installed CUDA version:
sudo /usr/local/cuda-X.Y/bin/cuda-uninstaller
For example, to remove CUDA 13.1, use /usr/local/cuda-13.1/bin/cuda-uninstaller. Subsequently, the script handles removal of all toolkit components installed through the runfile method.
Choose Your CUDA Installation Method
NVIDIA provides multiple installation methods with different trade-offs. Generally, the APT repository method offers the best balance of convenience and control for most users.
| Method | Channel | Version | Updates | Best For |
|---|---|---|---|---|
| APT Repository | NVIDIA CUDA Downloads | Latest stable | Automatic via apt upgrade | Most users who want straightforward installation and updates |
| Runfile | NVIDIA CUDA Downloads | Any version | Manual reinstallation | Systems without package manager access or custom installation paths |
| Conda | Anaconda NVIDIA Channel | Selected versions | Via conda update | Python developers using conda environments |
For most users, the APT repository method is recommended because it integrates with Ubuntu’s package management, handles dependencies automatically, and provides security updates through standard system updates.
This guide supports Ubuntu 22.04 LTS and 24.04 LTS installations. The NVIDIA CUDA repository provides packages specifically built for these Ubuntu LTS releases. Commands shown work identically on both supported LTS releases.
Install Prerequisites for CUDA
Before adding the NVIDIA repository, install the packages required for downloading keys, building kernel modules, and managing repositories:
sudo apt update
sudo apt install build-essential gcc linux-headers-$(uname -r) dirmngr ca-certificates software-properties-common dkms curl wget -y
Specifically, this command installs GCC (required for compiling CUDA programs), kernel headers (needed for DKMS to build driver modules), DKMS (for managing kernel modules that persist across kernel updates), and utilities for repository management.
Configure NVIDIA CUDA Repository
NVIDIA distributes CUDA through its own APT repository. Consequently, the cuda-keyring package handles GPG key management and repository configuration automatically, while the pin file ensures CUDA packages from NVIDIA take priority over Ubuntu’s default packages.
Download and Install CUDA Keyring
Choose the command matching your Ubuntu version. The cuda-keyring package configures the repository and manages GPG keys for package verification.
Ubuntu 24.04 LTS (Noble Numbat):
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
Ubuntu 22.04 LTS (Jammy Jellyfish):
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
Add Repository Pin File
Additionally, the pin file ensures APT prioritizes CUDA packages from NVIDIA’s repository over any conflicting packages from Ubuntu’s default repositories. Download and install the pin file for your Ubuntu version.
Ubuntu 24.04 LTS:
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
Ubuntu 22.04 LTS:
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin
sudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600
Refresh Package Cache
After adding the repository, update the package cache so APT recognizes the new CUDA packages:
sudo apt update
Subsequently, verify the NVIDIA repository appears in the output. You should see a line referencing developer.download.nvidia.com in the package list updates.
Install CUDA Toolkit and GPU Drivers
CUDA installation separates into toolkit components (compiler, libraries, development tools) and GPU drivers (kernel modules for hardware communication). Therefore, understanding the available packages helps you choose the right installation for your needs.
Available CUDA Packages
NVIDIA provides several package options with distinct purposes:
cuda-toolkit
- Installs CUDA SDK, libraries, compilers, and development tools
- Does not install or modify GPU drivers
- Recommended when you already have working NVIDIA drivers
cuda
- Meta-package that installs full CUDA Toolkit plus NVIDIA drivers
- Includes desktop components for display output
- Suitable for workstations with NVIDIA GPUs driving displays
nvidia-open
- Open-source kernel module for Turing and newer GPUs (RTX 20 series and later)
- Better compatibility with modern kernel features
- Tracks the newest supported open driver automatically
cuda-drivers
- Installs proprietary NVIDIA GPU drivers
- Supports all NVIDIA GPU architectures including older cards
- Required for Maxwell and Pascal GPUs (GTX 900/1000 series)
Check Available Package Versions
Before installing, review the available CUDA Toolkit and driver versions:
apt search cuda-toolkit | grep -E "^cuda-toolkit"
You should see output listing available toolkit versions:
cuda-toolkit/unknown 13.1.0-1 amd64 cuda-toolkit-12/unknown 12.9.1-1 amd64 cuda-toolkit-13/unknown 13.1.0-1 amd64 cuda-toolkit-13-0/unknown 13.0.2-1 amd64 cuda-toolkit-13-1/unknown 13.1.0-1 amd64
Similarly, check available driver versions:
apt search nvidia-driver | grep -E "^nvidia-driver-[0-9]+"
Install CUDA with Open Kernel Module (Turing and Newer GPUs)
For RTX 20 series and newer GPUs (Turing, Ampere, Ada Lovelace, Hopper, Blackwell architectures), install the toolkit with the open-source kernel module. This option provides better integration with modern kernel features and represents NVIDIA’s future driver direction:
sudo apt install cuda-toolkit nvidia-open
Notably, the nvidia-open meta-package tracks the newest supported open driver automatically. If you need a specific driver branch, install it explicitly (for example, nvidia-open-575).
Install CUDA with Proprietary Drivers (All GPU Architectures)
Alternatively, for older GPUs (Maxwell, Pascal) or when the open kernel module causes issues, install the toolkit with proprietary drivers:
sudo apt install cuda-toolkit cuda-drivers
Consequently, this installs the proprietary NVIDIA kernel module, which supports all GPU architectures from Maxwell onwards.
Install Specific Driver Version
When you need a particular driver version for compatibility or testing, specify both packages explicitly:
sudo apt install cuda-toolkit nvidia-driver-570
Replace 570 with your required version. Check available versions using the search command shown earlier.
Optional: Install GPUDirect Storage
GPUDirect Storage (GDS) enables direct data paths between GPU memory and NVMe storage, bypassing system memory for improved I/O performance in data-intensive workloads. Install GDS only after completing the CUDA Toolkit and driver installation:
sudo apt install nvidia-gds
Install nvidia-gds only after the driver installation completes. The nvidia-fs kernel module builds against the current driver, and installing out of order can cause application hangs.
Reboot to Load Kernel Modules
After installation completes, reboot your system to load the new NVIDIA kernel modules:
sudo reboot
The reboot is required because the NVIDIA driver consists of kernel modules that cannot be loaded while the old modules (or the nouveau driver) are in use.
Verify CUDA Installation
Once rebooting is complete, verify that both the NVIDIA drivers and CUDA Toolkit installed correctly.
Check NVIDIA Driver Status
The nvidia-smi command displays GPU information and confirms the driver loaded successfully:
nvidia-smi
You should see output showing your GPU model, driver version, and CUDA version:
+-----------------------------------------------------------------------------------------+ | NVIDIA-SMI 575.xx.xx Driver Version: 575.xx.xx CUDA Version: 13.1 | |-----------------------------------------+------------------------+----------------------+ | GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. | |=========================================+========================+======================| | 0 NVIDIA GeForce RTX 3060 Off | 00000000:01:00.0 Off | N/A | | 0% 35C P8 12W / 170W | 1MiB / 12288MiB | 0% Default | +-----------------------------------------+------------------------+----------------------+
If you see “NVIDIA-SMI has failed” or “No devices were found,” the driver did not load correctly. Check the troubleshooting section below.
Check CUDA Compiler Version
Verify the CUDA compiler is accessible and displays the expected version:
nvcc --version
Expected output:
nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2024 NVIDIA Corporation Built on ... Cuda compilation tools, release 13.x, V13.x.xxx Build cuda_13.x.r13.x/compiler.xxxxxxxx_0
However, if the command is not found, the CUDA binaries are not in your PATH. For APT installations, they should be available automatically. If using a runfile installation, see the environment variables section below.
Environment Variables for Runfile Installations
If you installed CUDA using the APT repository method (recommended), environment variables are configured automatically and you can skip this section.
However, for runfile installations, manually configure PATH and LD_LIBRARY_PATH by adding these lines to your ~/.bashrc:
export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
Finally, reload the configuration:
source ~/.bashrc
Test CUDA with Sample Programs
NVIDIA provides sample programs demonstrating CUDA capabilities. Clone the samples repository and build the device query sample to verify your installation works correctly:
git clone https://github.com/nvidia/cuda-samples.git
cd cuda-samples/Samples/1_Utilities/deviceQuery
make
Next, run the compiled sample:
./deviceQuery
Successful output ends with:
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 13.x, CUDA Runtime Version = 13.x Result = PASS
Once the result shows PASS, your CUDA installation is working correctly and ready for development.
Switch Between Kernel Module Types
Notably, after installation, you can switch between open and proprietary kernel modules without reinstalling the entire toolkit.
To switch to the open-source kernel module:
sudo apt install nvidia-open
To switch back to the proprietary kernel module:
sudo apt install nvidia-driver-575
Replace the driver version with your preferred branch. Subsequently, after switching, reboot to load the new kernel module.
Update CUDA Toolkit
NVIDIA regularly releases CUDA updates with performance improvements, bug fixes, and new features. Since you configured the NVIDIA repository, updates arrive through standard APT commands:
sudo apt update
sudo apt upgrade
Major version upgrades (for example, from 12.x to 13.x) may require reviewing NVIDIA’s release notes for breaking changes that could affect your applications.
Troubleshoot Common CUDA Issues
Driver Fails to Load After Reboot
If nvidia-smi fails after installation, check the kernel module status:
lsmod | grep nvidia
If no nvidia modules appear, the nouveau driver may be blocking NVIDIA. Check for nouveau:
lsmod | grep nouveau
If nouveau is loaded, blacklist it by creating a configuration file:
echo "blacklist nouveau" | sudo tee /etc/modprobe.d/blacklist-nouveau.conf
echo "options nouveau modeset=0" | sudo tee -a /etc/modprobe.d/blacklist-nouveau.conf
sudo update-initramfs -u
sudo reboot
Secure Boot Blocks Unsigned Modules
On systems with Secure Boot enabled, unsigned kernel modules cannot load. Check if Secure Boot is active:
mokutil --sb-state
If Secure Boot is enabled, you have two options: first, disable it in BIOS/UEFI settings, or alternatively, sign the NVIDIA kernel modules using Machine Owner Key (MOK). For development workstations, disabling Secure Boot is often the simpler solution.
DKMS Module Build Fails
If the NVIDIA module fails to build during installation, check DKMS status:
dkms status
Next, look for errors and check the build log:
cat /var/lib/dkms/nvidia/*/build/make.log
Common causes include missing kernel headers. Install them with:
sudo apt install linux-headers-$(uname -r)
Subsequently, rebuild the module:
sudo dkms autoinstall
Unable to Locate Package Errors
If APT cannot find CUDA packages, the repository may not be configured correctly. Verify the repository is present:
apt-cache policy cuda-toolkit
A working repository shows version candidates from the NVIDIA URL:
cuda-toolkit:
Installed: (none)
Candidate: 13.x.x-1
Version table:
13.x.x-1 600
600 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64 Packages
If no candidate appears, reinstall the cuda-keyring package and update:
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt update
Remove CUDA Toolkit
The following commands remove CUDA packages, NVIDIA drivers, and associated configuration. Make sure you want to completely remove your GPU development environment before proceeding.
To remove the CUDA Toolkit and NVIDIA drivers installed via APT:
sudo apt remove --purge cuda* nvidia* cuda-keyring
sudo apt autoremove --purge
Additionally, remove the repository pin file:
sudo rm /etc/apt/preferences.d/cuda-repository-pin-600
Next, refresh the package cache after removal:
sudo apt update
Finally, verify removal completed successfully:
apt-cache policy cuda-toolkit
The output should show no installation candidate:
N: Unable to locate package cuda-toolkit
Next Steps with CUDA on Ubuntu
Your Ubuntu system now runs a complete CUDA development environment with the nvcc compiler, GPU-accelerated libraries, and profiling tools. The APT repository configuration ensures you receive CUDA updates, security patches, and new features as NVIDIA releases them. To continue learning, explore the CUDA samples repository for working examples covering parallel algorithms, memory optimization, and library usage, or consult the NVIDIA CUDA documentation for API references and programming guides.
I got this error when trying to install GROMACS 2025 on my ubuntu 24.04
CMake Error at /usr/share/cmake-3.28/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find CUDAToolkit: Found unsuitable version “12.0.140”, but
required is at least “12.1” (found /usr/include)
Call Stack (most recent call first):
/usr/share/cmake-3.28/Modules/FindPackageHandleStandardArgs.cmake:598 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.28/Modules/FindCUDAToolkit.cmake:1009 (find_package_handle_standard_args)
cmake/gmxManageCuda.cmake:45 (find_package)
CMakeLists.txt:726 (include)
When I ran nvidia-smi, it showed 12.8. So I installed the CUDAToolKit-12.8 but it is not showing when I run the cmake command
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2025 NVIDIA Corporation
Built on Fri_Feb_21_20:23:50_PST_2025
Cuda compilation tools, release 12.8, V12.8.93
Build cuda_12.8.r12.8/compiler.35583870_0
Please how can I solve this Cmake error
Thanks for reporting this Charles. The error shows CMake is detecting CUDA 12.0.140 in
/usr/includeinstead of your installed 12.8 version, even thoughnvccconfirms 12.8 is present andnvidia-smireports the correct driver API version.CMake’s
FindCUDAToolkitmodule searches multiple paths and stops at the first match, which in your case is an older CUDA installation or leftover headers in/usr/include. Run this command to list all installed CUDA packages:If you see
cuda-toolkit-12-0or similar older packages, remove them with:After cleanup, explicitly tell CMake where to find CUDA 12.8 by setting the toolkit root when running cmake:
Or export the CUDA path before building:
Verify the symlink at
/usr/local/cudapoints tocuda-12.8:Let me know if the conflict persists after removing the old version.
Did on 22.04:
sudo apt autoremove cuda* nvidia* –purge
sudo apt install build-essential gcc dirmngr ca-certificates software-properties-common apt-transport-https dkms curl -y
curl -fSsL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/3bf863cc.pub | sudo gpg –dearmor | sudo tee /usr/share/keyrings/nvidia-drivers.gpg > /dev/null 2>&1
echo ‘deb [signed-by=/usr/share/keyrings/nvidia-drivers.gpg] https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/ /’ | sudo tee /etc/apt/sources.list.d/nvidia-drivers.list
sudo apt install nvidia-driver-535 cuda-drivers-535 cuda
But get:
~$ sudo apt install nvidia-driver-535 cuda-drivers-535 cuda
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
cuda-drivers-535 : Depends: nvidia-kernel-source-535 (>= 535.183.06) but it is not installable or
nvidia-kernel-open-535 (>= 535.183.06) but it is not installable
nvidia-dkms-535 : Depends: nvidia-kernel-source-535 but it is not installable or
nvidia-kernel-open-535 but it is not installable
nvidia-driver-535 : Depends: nvidia-kernel-source-535 (= 535.183.06-0ubuntu1) but it is not installable or
nvidia-kernel-open-535 (= 535.183.06-0ubuntu1) but it is not installable
nvidia-driver-560-open : Depends: libnvidia-gl-560 (= 560.35.03-0ubuntu1) but it is not installable
Depends: nvidia-dkms-560-open (= 560.35.03) but it is not installable
Depends: nvidia-kernel-common-560 (= 560.35.03) but it is not installable
Depends: libnvidia-compute-560 (= 560.35.03-0ubuntu1) but it is not installable
Depends: libnvidia-extra-560 (= 560.35.03-0ubuntu1) but it is not installable
Depends: nvidia-compute-utils-560 (= 560.35.03-0ubuntu1) but it is not installable
Depends: libnvidia-decode-560 (= 560.35.03-0ubuntu1) but it is not installable
Depends: libnvidia-encode-560 (= 560.35.03-0ubuntu1) but it is not installable
Depends: nvidia-utils-560 (= 560.35.03-0ubuntu1) but it is not installable
Depends: xserver-xorg-video-nvidia-560 (= 560.35.03-0ubuntu1) but it is not installable
Depends: libnvidia-cfg1-560 (= 560.35.03-0ubuntu1) but it is not installable
Depends: libnvidia-fbc1-560 (= 560.35.03-0ubuntu1) but it is not installable
Recommends: libnvidia-compute-560:i386 (= 560.35.03-0ubuntu1)
Recommends: libnvidia-decode-560:i386 (= 560.35.03-0ubuntu1)
Recommends: libnvidia-encode-560:i386 (= 560.35.03-0ubuntu1)
Recommends: libnvidia-fbc1-560:i386 (= 560.35.03-0ubuntu1)
Recommends: libnvidia-gl-560:i386 (= 560.35.03-0ubuntu1)
E: Unable to correct problems, you have held broken packages.
It seems that the packages for the NVIDIA 535 drivers may not be available in your current repository. To verify this, you can try searching for the packages with the following commands:
apt-cache search nvidia-kernel-sourceor
apt-cache search nvidia-kernel-source-535This will show you if the necessary packages are available. If nothing comes up, it may indicate that the 535 driver isn’t present in the current repository configuration.
As far as I know, the NVIDIA 535 drivers are not set to reach End-of-Life (EOL) on Linux until June 2026, so they should still be supported. If the packages aren’t available, it could be an issue with the repository or a temporary glitch.
Let me know what you find, and we can troubleshoot further if needed!