3 Quick Steps to Set Up NVIDIA CUDA Toolkit on Debian

3 Quick Steps to Set Up NVIDIA CUDA Toolkit on Debian

Looking to install the NVIDIA CUDA toolkit on Debian? You’re in the right place.

NVIDIA’s CUDA toolkit equips you with a suite of development tools essential for creating GPU-accelerated applications across desktops, embedded systems, and data centers. This guide is tailored for those using Debian and seeking to explore CUDA’s capabilities.

Throughout this tutorial, I’ll be using Debian 12 Bookworm as the primary example. However, I’ll also include relevant variations for Debian 10 and 11 users, ensuring the process is clear regardless of your Debian version.

What You’ll Need

To ensure a smooth setup of the CUDA toolkit on Debian, make sure you have the following:

  • Debian installed and running on your system (see guide)
  • Basic understanding of the command line interface and Linux commands (see guide)
  • Root access or sudo privileges (see guide)
  • A stable internet connection
  • A CUDA-compatible GPU installed in your system (see guide)

With these prerequisites in place, let’s dive into the first step of the installation process.

How to Set Up NVIDIA CUDA Toolkit on Debian: Step-By-Step

Step 1: Pre-installation Checks for NVIDIA CUDA Toolkit

Before diving into the installation, it’s crucial to ensure your system meets all requirements for the NVIDIA CUDA toolkit. Let’s go through each verification step.

  1. First, you’ll verify whether your GPU is capable of using CUDA. To check that, run this command:
lspci | grep -i nvidia

With this command, we’re trying to list all the information about the GPU you’re using on your device. You can also cross-reference your GPU model with NVIDIA’s list of CUDA-capable GPUs. If your GPU model is listed, it supports CUDA.

  1. Next, you can check if your current Linux version is compatible with CUDA. For that, display the information about your Linux distro with this command:
uname -m && cat /etc/*release
Display current Linux distribution information

If you’re using Debian 10, 11, or 12, then you don’t need to worry about this. In this guide, I am using Debian 12, which is compatible.

  1. The last thing to check is whether the correct kernel headers and development packages are installed. Check the current kernel version with this command:
uname -r
uname command to display kernel version in Debian
  1. To install CUDA, you require the same version of kernel headers and development packages as the output you got. You can install these necessary headers with this command:
sudo apt-get install linux-headers-$(uname -r)
Install latest kernel Linux headers in Debian

After completing these verifications, you can proceed to the installation. This tutorial will focus on using the distribution-specific package (DEB file) for Debian, though a runfile package is also an option.

Related: How to Extract Files from a DEB Package on Debian

Step 2: Downloading and Installing the CUDA Toolkit

Now that the preparatory steps are complete, we’ll move on to downloading and installing the CUDA toolkit on your Debian system.

  1. Before downloading anything, you must make sure your system is up to date. This ensures that all the packages available in your software repository list are in their latest version. Update the system with:
sudo apt update
sudo apt update command in Debian
  1. Create a new directory where you’ll store the downloaded file. I’m creating a directory called cuda. Create it and navigate to it with these commands:
mkdir cuda
cd cuda
  1. Next, you’ll download the local DEB file for CUDA. The file you must download depends on your system information (Distro, architecture, version). Download the DEB file with this command(s):
# Debian 12

wget https://developer.download.nvidia.com/compute/cuda/12.3.2/local_installers/cuda-repo-debian12-12-3-local_12.3.2-545.23.08-1_amd64.deb

# Debian 11

wget https://developer.download.nvidia.com/compute/cuda/12.3.2/local_installers/cuda-repo-debian11-12-3-local_12.3.2-545.23.08-1_amd64.deb

# Debian 10

wget https://developer.download.nvidia.com/compute/cuda/12.3.2/local_installers/cuda-repo-debian10-12-3-local_12.3.2-545.23.08-1_amd64.deb
Downloading CUDA toolkit on Debian


Important Tip

The download may take some time due to the file size.

  1. Once the download is finished, install CUDA’S public GPG key to your system of keyrings (to authenticate the packages) with this command:
sudo cp /var/cuda-repo-debian12-12-3-local/cuda-89C0CA71-keyring.gpg /usr/share/keyrings/ # Debian 12

sudo cp /var/cuda-repo-debian11-12-3-local/cuda-89C0CA71-keyring.gpg /usr/share/keyrings/ # Debian 11

sudo cp /var/cuda-repo-debian10-12-3-local/cuda-89C0CA71-keyring.gpg /usr/share/keyrings/ # Debian 10
Installing CUDA’S public GPG key to system's keyrings
  1. Then install the DEB package with the following command:
sudo dpkg -i cuda-repo-debian12-12-3-local_12.3.2-545.23.08-1_amd64.deb # Debian 12
sudo dpkg -i cuda-repo-debian11-12-3-local_12.3.2-545.23.08-1_amd64.deb # Debian 11
sudo dpkg -i cuda-repo-debian10-12-3-local_12.3.2-545.23.08-1_amd64.deb # Debian 10
install CUDA toolkit on Debian
  1. After that, you’ll need to copy CUDA’s keyrings to the directory where you store other keyrings. This is to verify that the packages you’re trying to install are from the authentic source. Copy the keyrings with this command:
sudo cp /var/cuda-repo-debian12-12-3-local/cuda-*-keyring.gpg /usr/share/keyrings/ # Debian 12

sudo cp /var/cuda-repo-debian11-12-3-local/cuda-*-keyring.gpg /usr/share/keyrings/ # Debian 11

sudo cp /var/cuda-repo-debian10-12-3-local/cuda-*-keyring.gpg /usr/share/keyrings/ # Debian 10
  1. Then you must add the contrib repository to your system. This repository is essential for software packages that have dependencies not present in the main Debian repository. Add contrib to your system with this command:
sudo add-apt-repository contrib
Adding the contrib repository to Debian
  1. Once you add it, you need to update your system once more so that the changes take effect. Update the system with:
sudo apt-get update
  1. The last step is to install the NVIDIA CUDA toolkit. Install it by running this command:
sudo apt-get -y install cuda-toolkit-12-3

Important Tip 

Replace ’12-3′ with the specific version you’re installing. The current version at the time of this writing is 12.3.

With these steps, you should have successfully installed the NVIDIA CUDA toolkit on your Debian system.

Related: Broken Packages on Linux? Here’s the Fix! – Saint

Step 3: Installing NVIDIA CUDA Drivers

Now that the CUDA toolkit is in place, the next step is to install the CUDA drivers on Debian. There are two types of drivers available: 1) legacy kernel module flavor and 2) open kernel module flavor. 

You can choose either based on your preference and switch between them if needed.

  1. For the legacy kernel version, run the following command:
sudo apt-get install -y cuda-drivers
  1. For the open kernel version, run the following commands:
sudo apt-get install -y nvidia-kernel-open-dkms
sudo apt-get install -y cuda-drivers
  1. To switch from the open kernel module to the legacy kernel module:
sudo apt-get remove --purge nvidia-kernel-open-dkms
sudo apt-get install --verbose-versions cuda-drivers-XXX
  1. To switch from the legacy kernel module to the open kernel module:
sudo apt-get --purge remove nvidia-kernel-dkms
sudo apt-get install --verbose-versions nvidia-kernel-open-dkms
sudo apt-get install --verbose-versions cuda-drivers-XXX

Note: Replace ‘XXX’ with the specific version number of the drivers.

Following these steps, you should have the appropriate NVIDIA CUDA drivers installed on your Debian system.


Related: How to Monitor Your Linux Server’s Resource Consumption

Conclusion

Well done on successfully installing the NVIDIA CUDA toolkit on your Debian system! You’re now all set to dive into the world of GPU-accelerated application development. The next step is to go through the official CUDA documentation and see what else you need to begin this journey. Happy coding!

If this guide helped you, please share it.

Related Posts