Jump to content

How to Install NVIDIA CUDA 12 on Debian 12


Linux Hint

Recommended Posts

The full form of CUDA is Compute Unified Device Architecture. CUDA is a parallel computing platform and programming model developed by NVIDIA. It is used to run the programs on NVIDIA Graphics Processing Units (GPUs) to speed up the computing applications dramatically.

In this article, we will show you how to install the latest version of CUDA (CUDA 12 at the time of this writing) on Debian 12.

Topic of Contents:

  1. Prerequisites
  2. Adding the NVIDIA CUDA 12 Official Package Repository to Debian 12
  3. Enabling the Official Debian Contrib Package Repository on Debian 12
  4. Installing NVIDIA CUDA 12 on Debian 12
  5. Adding NVIDIA CUDA to the PATH of Debian 12
  6. Adding the NVIDIA CUDA Libraries to the Debian 12 Library Search Path
  7. Running the NVIDIA CUDA Commands (i.e. nvcc) with Superuser/Root Privileges via udo
  8. Writing, Compiling, and Running a Simple CUDA Program
  9. Conclusion

Prerequisites:

To install the latest version of CUDA (CUDA 12), compile the CUDA programs, and run the CUDA programs on Debian 12, you need the following:

i) Installed NVIDIA GPU on your computer

ii) Installed NVIDIA GPU drivers on your Debian 12 system

NOTE: If you need any assistance in installing the NVIDIA GPU drivers on your Debian 12 system, read this article.

Adding the NVIDIA CUDA 12 Official Package Repository to Debian 12

Before installing NVIDIA CUDA 12 on Debian 12, you have to add the official NVIDIA CUDA package repository on your Debian 12 system.

First, visit the official NVIDIA CUDA Toolkit Archive from a web browser.

The latest version of NVIDIA CUDA is 12.3.0 at the time of this writing[1]. You can find other versions of NVIDIA CUDA here as well[2]. Click on the NVIDIA CUDA version that you want to install.

A screenshot of a computer Description automatically generated

Click on “Linux”.

A screenshot of a computer Description automatically generated

Select “x86_64” as the Architecture[1], “Debian” as the Distribution[2], “12” as the Version[3], and “deb” (network) as the Installer Type[4]. The DEB package URL that you need to download and install on your Debian 12 system to add the official NVIDIA CUDA repository[5] and the package name of the NVIDIA CUDA version that you want to install[6] should be displayed.

A screenshot of a computer Description automatically generated

Now, navigate to the “/tmp” directory as follows:

$ cd /tmp

To download the “cuda-keyring_1.1-1_all.deb” DEB package file to add the official package repository of NVIDIA CUDA, run the following command:

$ wget http://developer.download.nvidia.com/compute/cuda/repos/debian12/x86_64/cuda-keyring_1.1-1_all.deb

A screenshot of a computer Description automatically generated

To install the “cuda-keyring_1.1-1_all.deb” DEB package file to add the NVIDIA CUDA repository on Debian 12, run the following command:

$ sudo apt install /tmp/cuda-keyring_1.1-1_all.deb

The “cuda-keyring_1.1-1_all.deb” DEB package file should be installed and the official NVIDIA CUDA repository should be added to your Debian 12 system.

word-image-410507-7.png

Enabling the Official Debian Contrib Package Repository on Debian 12

Some of the dependency packages of NVIDIA CUDA are in the official Debian 12 contrib package repository. So, you have to enable it before you can install NVIDIA CUDA on Debian 12.

To enable the official Debian 12 contrib package repository, run the following command and press <Enter> once you’re prompted.

$ sudo add-apt-repository contrib

A screenshot of a computer Description automatically generated

The official Debian 12 contrib package repository should be enabled.

A screenshot of a computer Description automatically generated

Installing NVIDIA CUDA 12 on Debian 12

To install your desired version of NVIDIA CUDA (cuda-toolkit-12-3 in this case), run the following command:

$ sudo apt install cuda-toolkit-12-3

To confirm the installation, press “Y” and then press <Enter>.

word-image-410507-10.png

NVIDIA CUDA and all the required dependency packages are being downloaded from the internet. It takes a while to complete.

A screenshot of a computer Description automatically generated

NVIDIA CUDA and all the required dependency packages are being installed. It takes a while to complete.

A screenshot of a computer Description automatically generated

At this point, NVIDIA CUDA should be installed on your Debian 12 system.

A screenshot of a computer program Description automatically generated

Adding NVIDIA CUDA to the PATH of Debian 12

To be able to access the latest version of NVIDIA CUDA from the command line, you have to add the CUDA binary directory to the PATH of your Debian 12 system.

NVIDIA CUDA will be installed in the “/usr/local/” directory of Debian 12. Each version of CUDA has its own directory. As you can see, we have the “/usr/local/cuda-12.3” directory as we installed NVIDIA CUDA 12.3.

A screenshot of a computer Description automatically generated

To add the NVIDIA CUDA 12.3 binary directory to the PATH, create a new file which is “cuda-12.3.sh” in the “/etc/profile.d/” directory with the nano text editor as follows:

$ sudo nano /etc/profile.d/cuda-12.3.sh

Type in the following lines of codes in the “/etc/profile.d/cuda-12.3.sh” file:

export CUDA_VERSION="12.3"

export CUDA_HOME="/usr/local/cuda-${CUDA_VERSION}"

export PATH="${CUDA_HOME}/bin${PATH:+:${PATH}}"

Once you’re done, save the “cuda-12.3.sh” file by pressing <Ctrl> + X followed by “Y” and <Enter>.

A computer screen with text on it Description automatically generated

For the changes to take effect, reboot your Debian 12 system:

$ sudo reboot

Once your Debian 12 system boots, you should see that NVIDIA CUDA 12 is in the PATH of your Debian 12 system.

$ echo $CUDA_VERSION

$ echo $CUDA_HOME

$ echo $PATH

A screenshot of a computer Description automatically generated

You should be able to access the NVIDIA CUDA commands like “nvcc” as you can see in the following screenshot:

$ nvcc --version

A screenshot of a computer Description automatically generated

Adding the NVIDIA CUDA Libraries to the Debian 12 Library Search Path

To compile the NVIDIA CUDA programs, you need to add the NVIDIA CUDA library path to the Debian 12 library search path at times.

First, create a new file which is “cuda-12.3.conf” (as we installed NVIDIA CUDA 12.3) in the “/etc/ld.so.conf.d/” directory and open it with the nano text editor as follows:

$ sudo nano /etc/ld.so.conf.d/cuda-12.3.conf

A close up of a grey and black background Description automatically generated

Type in the NVIDIA CUDA library path in the file and press <Ctrl> + X followed by “Y” and <Enter> to save the file.

In our case, the NVIDIA CUDA library path is “/usr/local/cuda-12.3/lib64” (as we installed NVIDIA CUDA 12.3).

A screenshot of a computer Description automatically generated

For the changes to take effect, run the following command:

$ sudo ldconfig --verbose

The Debian 12 library database should be updated and your desired version of NVIDIA CUDA libraries should be added to the library path.

word-image-410507-21.png

Run the NVIDIA CUDA Commands (i.e. nvcc) with Superuser/Root Privileges via Sudo

At times, you may need to run some NVIDIA CUDA commands (i.e. nvcc) with superuser privileges. To run the NVIDIA CUDA commands with superuser/root privileges via sudo, you must add the NVIDIA CUDA “/usr/local/cuda-12.3/bin” binary directory (where your desired version of NVIDIA CUDA is installed) to the “/etc/sudoers” file.

First, open the “/etc/sudoers” configuration file with a text editor as follows:

$ sudo visudo -f /etc/sudoers

Add the “/usr/local/cuda-12.3/bin” text at the end of the “secure_path” of the “/etc/sudoers” file as marked in the following screenshot:

Once you’re done, press <Ctrl> + X followed by “Y” and <Enter> to save the “/etc/sudoers” file.

A screenshot of a computer Description automatically generated

Now, you can run the NVIDIA CUDA commands (i.e. nvcc) with superuser/root privileges via sudo.

$ sudo nvcc --version

A screenshot of a computer Description automatically generated

Writing, Compiling, and Running a Simple CUDA Program

Since you successfully installed the latest version of NVIDIA CUDA on your Debian 12 system, you can start writing your first CUDA program, compile it with the “nvcc” command, and run it.

Conclusion

In this article, we showed you how to add the official package repository of a specific version of NVIDIA CUDA 12 on Debian 12. We also showed you how to install your desired version of NVIDIA CUDA 12 on Debian 12. We showed you how to add the NVIDIA CUDA binary path to the PATH of Debian 12 as well as add the NVIDIA CUDA libraries to the library path of Debian 12. Finally, we showed you how to run the NVIDIA CUDA commands on Debian 12 with superuser/root privileges via sudo.

View the full article

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...