Developers working with NVIDIA GPUs need the CUDA Toolkit to build GPU-accelerated applications. Unlike AMD’s ROCm or the cross-platform OpenCL framework, CUDA works exclusively with NVIDIA hardware but offers deep integration with NVIDIA’s GPU architectures. The toolkit includes libraries, debugging and optimization tools, a compiler, and runtime libraries for GPU computing tasks like machine learning, scientific computing, and real-time data processing.
This guide covers installing the CUDA Toolkit on Ubuntu using NVIDIA’s official APT repository. This method provides access to the latest toolkit versions, updates, and security patches directly from NVIDIA. The instructions apply to CUDA 13.x series releases on Ubuntu 24.04 and 22.04 LTS, which are the currently supported Ubuntu releases for CUDA development.
Remove Existing CUDA and NVIDIA Installations
You can skip this section if you have a fresh system without any prior NVIDIA or CUDA installations. However, if you already have existing NVIDIA drivers or CUDA packages, remove them first to prevent potential conflicts and installation issues.
Remove NVIDIA Packages Installed via APT
If you installed NVIDIA drivers or CUDA using the APT package manager, use the following commands to remove all NVIDIA and CUDA packages cleanly. This approach removes the packages and their configuration files while avoiding unintended removal of unrelated system packages:
sudo apt remove --purge "*cuda*" "*cublas*" "*cufft*" "*cufile*" "*curand*" "*cusolver*" "*cusparse*" "*gds-tools*" "*npp*" "*nvjpeg*" "nsight*" "*nvvm*" "*nvidia*"
After removing the packages, clean up orphaned dependencies:
sudo apt autoremove --purge
The --purge flag removes configuration files along with the packages, ensuring a clean uninstallation. Additionally, the quoted wildcard patterns prevent shell expansion and allow APT to match all related packages precisely.
Remove NVIDIA Drivers Installed via Runfile
If you installed NVIDIA drivers using a runfile, the uninstallation process differs from APT-based installations. Runfile installations include an uninstaller script that handles removal:
Switch to a text console (Ctrl+Alt+F3), sign in, and stop the running display manager (for example, sudo systemctl stop gdm3 or sudo systemctl stop lightdm) before running the script because it will abort if X.Org or Wayland is active. After removal, reboot or start the display manager again.
sudo /usr/bin/nvidia-uninstall
This script removes the NVIDIA driver components installed through the runfile method, ensuring clean uninstallation without affecting system package management.
Never mix installation methods. If you used the APT repository method (recommended), do not attempt runfile uninstallation commands. Mixing installation methods can create conflicts and incomplete removals.
Remove the 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 number:
sudo /usr/local/cuda-X.Y/bin/cuda-uninstaller
For example, to remove CUDA 13.0, use /usr/local/cuda-13.0/bin/cuda-uninstaller. The script handles removal of all toolkit components installed through the runfile method.
Install CUDA Toolkit via APT commands
As previously discussed, installing CUDA directly from the NVIDIA CUDA repository is the most efficient approach. This method ensures you receive any new enhancements, bug fixes, security updates, and features first.
Ubuntu desktops and servers typically ship without CUDA, but confirm before installing new packages so you know whether you are upgrading or performing a clean setup. Run the following command; if it returns the installed version, you already have CUDA, and you can decide whether removal or an in-place upgrade makes more sense.
nvcc --version
If the command is not found, proceed with the installation steps below. On systems with an older toolkit installed, compare the reported version to the CUDA 13.x release you plan to deploy.
Prepare Ubuntu for the NVIDIA CUDA Repository
Before starting the installation process, ensure your system has the necessary packages. These packages might already be installed, but verifying doesn’t hurt. Run the following command in your terminal:
sudo apt install build-essential gcc dirmngr ca-certificates software-properties-common dkms curl -y
This command installs several essential packages: dirmngr (for managing keys), ca-certificates (for handling SSL certificates), software-properties-common (for managing software repositories), dkms (for managing kernel modules), and curl (for downloading files from the internet).
Import GPG Key for NVIDIA CUDA Repository
Security is a top priority during software installations. The modern approach to importing NVIDIA’s GPG key uses the cuda-keyring package, which handles key management automatically and ensures you receive key updates. Choose the command for your Ubuntu version.
For Ubuntu 24.04 Noble Numbat, use the following command:
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
For Ubuntu 22.04 Jammy Jellyfish, use the following command:
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
CUDA Toolkit only supports Ubuntu LTS releases. Currently supported versions are Ubuntu 24.04 and 22.04 LTS. Ubuntu 20.04 LTS reached end of standard support in April 2025 and is no longer supported by CUDA. If you’re running Ubuntu 20.04, upgrade to Ubuntu 22.04 or 24.04 to continue receiving CUDA updates.
Import NVIDIA Repository
After installing the cuda-keyring package, the NVIDIA repository is automatically configured. However, you still need to add the pin file to prioritize CUDA packages from the official repository. Choose the command for your Ubuntu version.
For Ubuntu 24.04 Noble Numbat, use the following command:
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
For Ubuntu 22.04 Jammy Jellyfish, use the following command:
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
Update Package Cache
After adding the NVIDIA repository, update your system’s package list. This ensures your system recognizes the new packages available in the NVIDIA repository. Run the following command:
sudo apt update
This command fetches the latest package information from all configured repositories, including the newly added NVIDIA repository.
Install CUDA Toolkit
The CUDA installation separates into two components: the CUDA Toolkit (development tools, libraries, compilers) and the NVIDIA GPU drivers. Understanding the available packages helps you choose the right installation for your needs.
If you simply want the newest toolkit that NVIDIA publishes in this repository, install the rolling meta-package:
sudo apt install cuda-toolkit
This guide focuses on the CUDA 13.x series, so the remaining commands pin cuda-toolkit-13-0 to keep that major version in place even after newer releases ship.
Understanding CUDA Package Options
NVIDIA provides several package options with distinct purposes. Most users should install cuda-toolkit for development work, as it includes all SDK components without modifying your existing display drivers:
- cuda-toolkit: Installs the CUDA SDK, libraries, compilers, and development tools without drivers (recommended for most users)
- cuda: Meta-package that installs the full CUDA Toolkit plus NVIDIA drivers and desktop components
- cuda-drivers: Installs NVIDIA GPU drivers without specifying a version
- nvidia-driver-XXX: Installs a specific NVIDIA driver version (e.g., nvidia-driver-550)
- nvidia-gds: Optional GPUDirect Storage support for high-performance storage access
Check Available Packages
Before installing, review the available CUDA Toolkit and driver versions using APT search commands:
apt search cuda-toolkit
apt search cuda-drivers
apt search nvidia-driver
apt search nvidia-driver-open

Install CUDA Toolkit and Drivers
NVIDIA now supports two kernel module types for modern GPUs. Choose the installation method that matches your hardware and requirements.
Option 1: Install CUDA Toolkit with Open Kernel Module (Recommended for Turing GPUs and Newer)
The open-source kernel module provides better compatibility with modern kernel features and represents NVIDIA’s future direction. NVIDIA’s official installer instructions pair the toolkit with the nvidia-open meta-package, which always tracks the newest supported open driver:
sudo apt install cuda-toolkit-13-0 nvidia-open
If you must stay on a specific open-driver branch, install that package explicitly instead (for example, sudo apt install cuda-toolkit-13-0 nvidia-driver-560-open).
Option 2: Install CUDA Toolkit with Proprietary Kernel Module
The proprietary module supports all NVIDIA GPUs including older architectures. To install the toolkit and proprietary drivers, run:
sudo apt install cuda-toolkit-13-0 cuda-drivers
Option 3: Install Specific Driver Version
When you need a particular driver version for compatibility or testing, specify both the toolkit and driver version explicitly. Replace 550 with your preferred version (545, 535, 530, etc.):
sudo apt install cuda-toolkit-13-0 nvidia-driver-550
Optional: Install GPUDirect Storage
GPUDirect Storage (GDS) enables direct data paths between GPU memory and storage, bypassing system memory for improved I/O performance. Install GDS only after the CUDA Toolkit and drivers are fully installed:
sudo apt install nvidia-gds
Installing nvidia-gds before completing the driver installation can cause application hangs. The nvidia-fs kernel module builds against the current driver, so follow the installation order carefully.
Switching Between Kernel Module Types
After installation, you can switch between open and proprietary kernel modules without reinstalling. To switch to the open kernel module, reinstall the nvidia-open meta package:
sudo apt install nvidia-open
Alternatively, to switch back to the proprietary kernel module:
sudo apt install nvidia-driver-XXX
When you need to pin a specific open driver, substitute nvidia-driver-XXX-open for nvidia-open (for example, nvidia-driver-560-open) so the branch stays consistent. Remember to reboot after switching to load the new kernel module.
Once installed, you need to reboot your system:
sudo reboot
Verify CUDA Installation and GPU Status
After installing CUDA on Ubuntu, verify the installation and understand key tools to enhance your development experience and ensure everything works correctly.
Environment Variables for Runfile Installations
If you installed CUDA using the APT repository method (the recommended approach covered in this guide), environment variables are already configured correctly, and you can skip to the verification steps below. The system automatically finds CUDA tools and libraries through standard package paths.
However, if you used the runfile installation method instead, you must manually configure PATH and LD_LIBRARY_PATH environment variables. Add the following lines to your ~/.bashrc or ~/.profile file and replace 13.0 with the exact CUDA 13.x release you installed:
export PATH=/usr/local/cuda-13.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-13.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
After adding these lines, reload the shell configuration file you edited (typically ~/.bashrc; log out and back in if you modified ~/.profile):
source ~/.bashrc
Check GPU Capabilities with NVIDIA CUDA
Before writing CUDA programs, understand your GPU’s capabilities. Different GPUs support different CUDA versions and have varying numbers of cores, memory sizes, and features. Use the nvidia-smi command to get detailed information about your GPU:
nvidia-smi
This command provides information about your GPU’s name, total memory, CUDA version, and more. Understanding your GPU’s capabilities helps you write more efficient CUDA programs.
CUDA Toolkit Documentation
The CUDA Toolkit has extensive documentation, including a programming guide, best practices guide, and API references. Familiarizing yourself with these resources is beneficial. Access the documentation online on the NVIDIA CUDA Toolkit Documentation page.
CUDA Samples and Examples
NVIDIA provides comprehensive sample programs demonstrating various aspects of CUDA programming, from basic concepts to advanced optimization techniques. These samples now reside in the official NVIDIA CUDA Samples repository on GitHub. To get started, clone the repository to access hundreds of working examples covering device queries, parallel algorithms, GPU optimization, and library usage:
git clone https://github.com/nvidia/cuda-samples.git
cd cuda-samples
The repository includes complete build instructions and documentation for each sample. To verify your installation works correctly, start with the deviceQuery and bandwidthTest samples before exploring more advanced examples.
Update NVIDIA Cuda Toolkit
NVIDIA regularly releases new CUDA Toolkit versions with performance improvements, bug fixes, and new features. Keeping your CUDA installation current lets you use these enhancements. Since you’ve set up your system to receive updates directly from the NVIDIA CUDA repository, you can easily update your CUDA installation using the APT package manager:
sudo apt update
sudo apt upgrade
Exploring CUDA Libraries with NVIDIA CUDA
CUDA offers several libraries that provide high-level functionalities for common computational tasks like linear algebra, Fourier transforms, and deep learning. Libraries such as cuBLAS, cuFFT, and cuDNN are highly optimized, saving development time and effort. The CUDA Toolkit documentation contains more details about these libraries.
Debugging and Profiling CUDA Programs on Ubuntu
Debugging and profiling are essential for optimizing CUDA applications. NVIDIA provides modern tools integrated with the CUDA Toolkit for detailed performance analysis and debugging. Additionally, Nsight Compute offers kernel-level profiling with detailed metrics for compute workloads, while Nsight Systems provides system-wide performance analysis across CPU and GPU activity. For command-line debugging, cuda-gdb delivers familiar GDB-style debugging capabilities specifically designed for CUDA applications, allowing you to inspect GPU state, set breakpoints in kernel code, and diagnose runtime issues.
Access these tools through the CUDA Toolkit installation at /usr/local/cuda-13.0/bin for command-line interfaces, or launch the graphical versions from your applications menu after installation.
Next Steps with CUDA on Ubuntu
The CUDA Toolkit provides a maintainable development environment for GPU-accelerated applications on Ubuntu. This installation process covers repository configuration using the modern cuda-keyring approach, driver selection between open and proprietary kernel modules, and optional GPUDirect Storage for high-performance I/O workloads. Regular updates through the APT package manager ensure you receive the latest improvements, security patches, and feature additions from NVIDIA. Your Ubuntu system now runs a complete CUDA development environment with access to comprehensive tooling, libraries, and the official samples repository for GPU computing projects.
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!