DebianDebian Based

How To Install Nvidia CUDA on Debian 12

Install Nvidia CUDA on Debian 12

NVIDIA’s Compute Unified Device Architecture (CUDA) is a parallel computing platform and application programming interface (API) model that allows developers to use NVIDIA GPUs for general-purpose processing. Whether you’re a developer aiming to harness GPU power for deep learning, scientific computations, or graphics rendering, installing CUDA on your Debian 12 system is a vital step. This guide provides a detailed, step-by-step process to install CUDA on Debian 12, ensuring compatibility and optimal performance.

Prerequisites

System Requirements

Before diving into the installation process, ensure your system meets the necessary requirements:

  • Supported NVIDIA GPU: Verify that your GPU is CUDA-capable by referring to the official NVIDIA CUDA GPUs list.
  • Operating System: Debian 12 “Bookworm” with the latest updates installed.
  • Minimum Specifications: Adequate CPU, RAM (at least 8GB recommended), and sufficient disk space (minimum 2GB free for CUDA installation).

Pre-Installation Setup

Ensure your system is prepared for the installation:

  • Check GPU Compatibility: Run the command lspci | grep -i nvidia to confirm the presence of an NVIDIA GPU.
  • Verify Existing Drivers: Use nvidia-smi to check if NVIDIA drivers are already installed and functioning.
  • Required Disk Space: Ensure you have at least 2GB of free space for the CUDA toolkit and associated libraries.

Preparing Your System

Installing Essential Packages

Begin by installing the necessary dependencies and updating your package manager:

  1. Update your package list:
sudo apt update
  1. Install build essentials and kernel headers:
sudo apt install -y build-essential linux-headers-$(uname -r)
  1. Install additional dependencies:
sudo apt install -y dkms libglvnd-dev pkg-config

Configuring Repository Sources

To access the latest CUDA packages, add the official NVIDIA CUDA repository to your system:

  1. Download the NVIDIA CUDA keyring package:
wget https://developer.download.nvidia.com/compute/cuda/repos/debian12/x86_64/cuda-keyring_1.1-1_all.deb
  1. Install the keyring package:
sudo dpkg -i cuda-keyring_1.1-1_all.deb
  1. Add the NVIDIA repository to your sources list:
echo 'deb [signed-by=/usr/share/keyrings/cuda-keyring.gpg] https://developer.download.nvidia.com/compute/cuda/repos/debian12/x86_64/ /' | sudo tee /etc/apt/sources.list.d/cuda.list
  1. Update the package list to include the new repository:
sudo apt update

Installing NVIDIA Drivers

Driver Installation Methods

There are two primary methods to install NVIDIA drivers on Debian 12:

  • Using Debian Repository: This method leverages the stable NVIDIA drivers provided by Debian.
  • Using NVIDIA’s Official Repository: Ideal for obtaining the latest drivers not yet available in Debian’s repositories.

Installing via Debian Repository

  1. Install the NVIDIA driver package:
sudo apt install -y nvidia-driver
  1. Blacklist the open-source Nouveau driver to prevent conflicts:
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
  1. Update the initramfs:
sudo update-initramfs -u

Installing via NVIDIA’s Official Repository

  1. Download the latest driver from the NVIDIA website.
  2. Make the installer executable:
chmod +x NVIDIA-Linux-x86_64-*.run
  1. Run the installer:
sudo ./NVIDIA-Linux-x86_64-*.run
  1. Follow the on-screen instructions to complete the installation.

Post-Driver Installation

After installing the drivers, perform the following steps to ensure proper configuration:

    • Reboot your system to load the new drivers:
sudo reboot
    • Verify the driver installation:
nvidia-smi

You should see a detailed summary of your GPU, driver version, and CUDA version.

Installing CUDA Toolkit

CUDA Installation Process

With the NVIDIA drivers in place, proceed to install the CUDA toolkit:

  1. Install the CUDA toolkit and drivers:
sudo apt install -y cuda-toolkit-12-5

This command installs CUDA version 12.5. Replace with your desired version if necessary.

  1. Confirm the installation:
dpkg -l | grep cuda

Ensure that the CUDA packages are listed and installed correctly.

Environment Configuration

To use CUDA tools from the command line, update your environment variables:

  1. Open the profile configuration file:
sudo nano /etc/profile.d/cuda.sh
  1. Add the following lines to set the CUDA environment variables:
export CUDA_HOME=/usr/local/cuda-12.5
export PATH=${CUDA_HOME}/bin:${PATH}
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64:${LD_LIBRARY_PATH}
  1. Save and close the file by pressing Ctrl + X, then Y, and Enter.
  2. Make the script executable:
sudo chmod +x /etc/profile.d/cuda.sh
  1. Reload the profile to apply changes:
source /etc/profile.d/cuda.sh

Testing and Verification

CUDA Installation Verification

Ensure that CUDA is installed correctly by performing the following checks:

  1. Check the CUDA version:
nvcc --version

You should see output indicating the CUDA compiler version.

  1. Run NVIDIA System Management Interface:
nvidia-smi

Verify that your GPU is recognized and the CUDA version matches the installed toolkit.

    • Execute a sample CUDA program:
  1. Clone the CUDA samples repository:
git clone https://github.com/NVIDIA/cuda-samples.git
  1. Navigate to the deviceQuery sample:
cd cuda-samples/Samples/1_Utilities/deviceQuery
  1. Compile the sample:
make
  1. Run the sample:
./deviceQuery

A successful run will display detailed information about your CUDA-capable device.

Advanced Configuration

Performance Optimization

Enhance the performance of your CUDA applications with the following optimizations:

  • Update CUDA Drivers: Regularly check for and install the latest CUDA drivers to benefit from performance improvements and bug fixes.
  • Enable GPU Boost: Adjust GPU settings to maximize performance without overheating.
  • Optimize Compiler Flags: Use appropriate nvcc compiler flags such as -O3 for optimization.
  • Manage Power Settings: Configure your system’s power management settings to prioritize performance over energy saving.

Troubleshooting Guide

Encountering issues during installation is common. Here are some common problems and their solutions:

  • Driver Installation Errors: Ensure that all dependencies are installed and that the Nouveau driver is properly blacklisted.
  • CUDA Toolkit Not Recognized: Verify that environment variables are correctly set and that the profile script is executed.
  • Sample Programs Fail to Compile: Confirm that development tools like gcc are installed and compatible with your CUDA version.
  • System Doesn’t Recognize GPU: Recheck the driver installation and ensure that the GPU is properly seated and enabled in BIOS.

Congratulations! You have successfully installed CUDA. Thanks for using this tutorial for installing the latest version of Nvidia CUDA on Debian 12 “Bookworm”. For additional help or useful information, we recommend you check the official Nvidia website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button