How To Install Nvidia CUDA on Debian 11
In this tutorial, we will show you how to install Nvidia CUDA on Debian 11. In the world of high-performance computing, NVIDIA CUDA has emerged as a powerful framework that leverages the parallel computing capabilities of NVIDIA GPUs. Debian 11, the latest version of the popular Linux distribution, provides a stable and reliable platform for running CUDA applications.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of GitHub Desktop on a Debian 11 (Bullseye).
Prerequisites
- A server running one of the following operating systems: Debian 11.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Nvidia CUDA.
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Nvidia CUDA on Debian 11 Bullseye
Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt
commands in the terminal:
sudo apt update sudo apt upgrade sudo apt sudo apt install build-essential gcc g++ make linux-headers-$(uname -r)
Step 2. Blacklisting Conflicting Kernel Modules.
Create a new file to blacklist the Nouveau driver:
nano /etc/modprobe.d/blacklist-nouveau.conf
Add the following lines to the file:
blacklist nouveau options nouveau modeset=0
Save the file and exit the editor then, update the initramfs to apply the changes:
sudo update-initramfs -u
Step 3. Installing Nvidia CUDA on Debian 11.
To use CUDA, you need to install the appropriate NVIDIA GPU driver. Now visit the official NVIDIA website and download the latest stable driver version compatible with your GPU and Debian 11:
wget https://developer.download.nvidia.com/compute/cuda/12.1.1/local_installers/cuda_12.1.1_530.30.02_linux.run
Navigate to the directory containing the downloaded installer. Make the installer executable:
chmod +x cuda_12.1.1_530.30.02_linux.run
Run the installer with root privileges:
sudo sh cuda_12.1.1_530.30.02_linux.run
During the installation, you’ll be prompted to accept the license agreement. Read the license agreement carefully and proceed with the installation.
Choose the installation type based on your requirements. For most users, the default options should suffice.
Next, setting up the environment variables:
nano ~/.bashrc
Append the following lines at the end of the file:
export PATH=/usr/local/cuda/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
Save the file and exit the editor. Update the environment variables by running:
source ~/.bashrc
To ensure that CUDA is installed correctly, run the following command:
nvcc --version
Step 4. Compiling and Running a CUDA Example Program.
To test your CUDA installation, let’s compile and run a simple CUDA example program:
- Downloading a Sample CUDA Program:
Visit the NVIDIA CUDA Samples GitHub repository and download the desired example program.
- Compiling the Program with
nvcc
:
Open a terminal and navigate to the directory containing the downloaded program. Compile the program using nvcc
:
nvcc your_program.cu -o your_program
- Running the CUDA Program:
Execute the compiled program:
./your_program
- Verifying the Output:
Check the program’s output to ensure that it runs successfully and produces the expected results.
Step 5. Troubleshooting Common Issues.
Despite following the steps outlined above, you may encounter issues during the installation process. Here are some troubleshooting tips:
- Fixing CUDA Library Path Issues: If you encounter library path issues, ensure that the
LD_LIBRARY_PATH
the environment variable is set correctly. - Handling Compatibility Problems: Verify that your GPU is supported by the installed NVIDIA driver and CUDA version. Refer to the official documentation for compatibility information.
- Addressing Compilation Errors: If you encounter compilation errors, ensure that your development environment is set up correctly, including the required packages and libraries.
Congratulations! You have successfully installed CUDA. Thanks for using this tutorial for installing the latest version of Nvidia CUDA on Debian 11 Bullseye. For additional help or useful information, we recommend you check the official Nvidia website.