DebianDebian Based

How To Install Nvidia CUDA on Debian 13

Install Nvidia CUDA on Debian 13

If you run machine learning workloads, video encoding, or scientific simulations, your NVIDIA GPU is sitting idle without CUDA. CUDA (Compute Unified Device Architecture) is NVIDIA’s parallel computing platform that unlocks the raw processing power of your GPU for general-purpose workloads — and getting it working on Debian 13 Trixie is more straightforward than you might think.

This guide walks you through every step to install Nvidia CUDA on Debian 13 from scratch — from enabling the right repositories to verifying the nvcc compiler — using tested commands drawn directly from NVIDIA’s official documentation and real-world Debian 13 Trixie deployments.

Whether you’re setting up a deep learning rig, a GPU-accelerated server, or just experimenting with CUDA programming, this Linux server tutorial gives you a clean, working environment by the end. Let’s get into it.

Prerequisites Before You Begin

Before you dive in, make sure your system checks all these boxes. Skipping any of these will cost you time later.

  • Operating System: Debian 13 “Trixie” (desktop or server edition)
  • NVIDIA GPU: Must be a CUDA-enabled card (Kepler architecture or newer); GTX 16xx and all RTX cards qualify
  • Driver compatibility: NVIDIA 590.xx drivers required for CUDA 13.1; NVIDIA 580.xx for CUDA 13.0
  • Sudo or root access: Every command below requires elevated privileges
  • Internet connection: Needed to pull packages from NVIDIA’s and Debian’s repositories
  • Secure Boot awareness: If Secure Boot is enabled, NVIDIA kernel modules may fail to load — enroll a Machine Owner Key (MOK) during installation
  • No previous CUDA installation: If upgrading, purge old packages first:
    sudo apt remove 'cuda*' 'nvidia*' --purge && sudo apt autoremove --purge

Verify Your GPU Is CUDA-Compatible

Run this command to confirm your system sees an NVIDIA GPU:

lspci | grep -i nvidia

You should see output similar to:

01:00.0 VGA compatible controller: NVIDIA Corporation GA106 [GeForce RTX 3060] (rev a1)

If you get no output, run sudo update-pciids to refresh the hardware database, then try again.

Step 1: Update Your Debian 13 System

Always start with a full system update. This step ensures your kernel, headers, and package metadata are current — which prevents dependency conflicts during driver and CUDA installation.

sudo apt update && sudo apt upgrade -y

If the upgrade pulls in a new kernel version, reboot immediately before continuing:

sudo reboot

This matters because NVIDIA drivers compile kernel modules via DKMS. If your running kernel doesn’t match your installed kernel headers, the build will fail. After rebooting, confirm your kernel version:

uname -r

Make a note of this version — you’ll need it when installing kernel headers in the next step.

Step 2: Install Required Build Dependencies

Now install the build tools and kernel headers DKMS needs to compile the NVIDIA kernel module.

sudo apt install -y build-essential dkms linux-headers-$(uname -r) ca-certificates curl gpg

Here’s what each package does:

  • build-essential — installs GCC, make, and related compiler tools required to build kernel modules
  • dkms — Dynamic Kernel Module Support; automatically recompiles NVIDIA modules after every kernel update
  • linux-headers-$(uname -r) — kernel header files matching your currently running kernel, required for module compilation
  • ca-certificates, curl, gpg — tools for downloading and verifying NVIDIA’s GPG signing key over HTTPS

Expected output after the command completes:

Processing triggers for man-db ...
Processing triggers for dkms ...

If you see any “Unable to locate package” errors, confirm your repositories are up to date by re-running sudo apt update.

Step 3: Enable contrib and non-free Repositories

NVIDIA’s proprietary driver lives outside Debian’s main (free software) repository. You need to enable contrib, non-free, and non-free-firmware components to access it.

Debian 13 uses the modern DEB822 format for sources. Edit it with this single command:

sudo sed -i 's/Components: main/Components: main contrib non-free non-free-firmware/' /etc/apt/sources.list.d/debian.sources

Then refresh your package cache:

sudo apt update

Confirm the change took effect:

grep Components /etc/apt/sources.list.d/debian.sources

Expected output:

Components: main contrib non-free non-free-firmware

Why this matters: Without non-free, APT cannot see the nvidia-driver or nvidia-cuda-toolkit packages at all. This is the most common reason beginners hit “Unable to locate package nvidia-driver” errors.

Step 4: Disable the Nouveau Open-Source Driver

The Nouveau driver is the open-source NVIDIA driver that Debian loads by default. It conflicts directly with NVIDIA’s proprietary driver — you cannot run both simultaneously.

The NVIDIA driver package typically blacklists Nouveau automatically, but you should do this manually to avoid a black screen on reboot.

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
sudo update-initramfs -u

What these commands do:

  • blacklist nouveau — tells the kernel not to load the Nouveau module at boot
  • options nouveau modeset=0 — disables Nouveau’s kernel mode setting as a secondary safeguard
  • update-initramfs -u — rebuilds the initial RAM disk so the blacklist takes effect at the next boot

Now reboot:

sudo reboot

After rebooting, confirm Nouveau is no longer loaded:

lsmod | grep nouveau

This command should return no output. If you still see Nouveau modules, check your /etc/modprobe.d/ directory for conflicting configuration files.

Step 5: Add the NVIDIA CUDA Repository and Install the Driver

You have two solid installation paths. Choose based on your priorities:

Method Best For CUDA Version
Debian default repo Production stability, conservative updates CUDA 12.4 (Trixie)
NVIDIA official repo Latest CUDA, newest GPU support (RTX 50xx) CUDA 13.x

Option A — Install from Debian’s Default Repository (Stable)

This is the simplest method and requires no additional repository setup:

sudo apt install -y nvidia-driver nvidia-cuda-toolkit nvidia-cuda-dev

When installed this way, Debian places nvcc in /usr/bin and CUDA files under /usr/lib/cuda — both are in your default PATH, so no environment variable configuration is needed.

Reboot after installation:

sudo reboot

Option B — Install from NVIDIA’s Official Repository (Latest)

Use this method if you need CUDA 13.x, the latest driver features, or support for newer GPU architectures like the RTX 50xx series.

Import the NVIDIA GPG Signing Key

curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/debian13/x86_64/8793F200.pub | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-cuda.gpg

The gpg --dearmor flag converts the ASCII key to binary format that APT requires for signed repository verification.

ARM64 users: Replace x86_64 with sbsa in the URL above.

Add the NVIDIA CUDA Repository

cat <<EOF | sudo tee /etc/apt/sources.list.d/nvidia-cuda.sources
Types: deb
URIs: https://developer.download.nvidia.com/compute/cuda/repos/debian13/x86_64/
Suites: /
Signed-By: /usr/share/keyrings/nvidia-cuda.gpg
EOF

Note the Suites: / — NVIDIA uses a flat repository structure, which is why there is no traditional suite name like trixie here.

Update and Install

sudo apt update
sudo apt install -y cuda nvidia-driver

The cuda metapackage pulls in the full CUDA toolkit, development headers, runtime libraries, and the nvcc compiler.

Reboot to activate the drivers:

sudo reboot

Secure Boot note: If your BIOS has Secure Boot enabled, the installer will prompt you to create a MOK password. You must select “Enroll MOK” from the blue UEFI screen on the next reboot, or the NVIDIA kernel modules will not load.

Step 6: Configure CUDA Environment Variables

Skip this step if you used Option A (Debian default repo). The Debian-packaged installation handles paths automatically.

If you used Option B (NVIDIA’s repository), CUDA installs to /usr/local/cuda/ — which is not in your default PATH. Configure it permanently for all users:

sudo tee /etc/profile.d/cuda.sh <<EOF
export PATH=/usr/local/cuda/bin:\$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:\$LD_LIBRARY_PATH
EOF

Apply it to your current session without logging out:

source /etc/profile.d/cuda.sh

What each variable does:

  • PATH — lets you run nvcc, nvprof, and other CUDA tools directly from the terminal
  • LD_LIBRARY_PATH — tells the dynamic linker where to find CUDA shared libraries (.so files) at runtime

Verify the path is set correctly:

which nvcc

Expected output:

/usr/local/cuda/bin/nvcc

Step 7: Verify Your CUDA Installation on Debian 13

You’ve done the work — now confirm everything is functioning correctly before you build anything on top of it.

Check NVIDIA Driver and GPU Status

nvidia-smi

Expected output (your GPU model and versions will differ):

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 5xx.xx  Driver Version: 5xx.xx  CUDA Version: 13.x              |
+-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
|  0  NVIDIA GeForce RTX 3060  Off | 00000000:05:00.0 Off |                  N/A |
|  0%   42C    P8    10W / 170W |      1MiB / 12037MiB |      0%      Default |
+-----------------------------------------------------------------------------+

If nvidia-smi returns “command not found”, the driver did not load. See the Troubleshooting section below.

Check the CUDA Compiler Version

nvcc --version

Expected output:

nvcc: NVIDIA (R) Cuda compiler driver
Cuda compilation tools, release 12.4, V12.4.131
Build cuda_12.4.r12.4/compiler.34097967_0

Run the deviceQuery Sample (Recommended)

This step compiles and runs NVIDIA’s official hardware query tool, proving your full CUDA stack — compiler, runtime, and driver — communicates correctly:

git clone https://github.com/NVIDIA/cuda-samples.git
cd cuda-samples/Samples/1_Utilities/deviceQuery
cmake ./
make
./deviceQuery

The final line of output should read:

Result = PASS

A PASS result confirms your Nvidia CUDA on Debian 13 setup is fully operational.

Step 8: Post-Installation Enhancements (Optional)

You have a working CUDA environment. Here are a few high-value additions worth considering.

Install cuDNN for Deep Learning

cuDNN (CUDA Deep Neural Network Library) is required by TensorFlow, PyTorch, and most ML frameworks. Download it from NVIDIA’s developer portal (free registration required) at developer.nvidia.com/cudnn, then install the .deb package.

Enable GPU-Accelerated Docker Containers

Install the NVIDIA Container Toolkit to pass your GPU into Docker containers:

sudo apt install -y nvidia-container-toolkit
sudo systemctl restart docker

This is ideal for reproducible ML development environments where you want GPU access inside containers without polluting your host system.

Test With PyTorch

Quickly validate that a real ML framework sees your GPU:

python3 -c "import torch; print('CUDA available:', torch.cuda.is_available()); print('GPU:', torch.cuda.get_device_name(0))"

Expected output:

CUDA available: True
GPU: NVIDIA GeForce RTX 3060

Troubleshooting Common CUDA Issues on Debian 13

Even a careful installation can hit snags. Here are the five most common issues and exactly how to fix them.

1. nvidia-smi: command not found or GPU Not Detected

The NVIDIA kernel module didn’t load. Check if it’s present:

lsmod | grep nvidia

If no output appears, check the kernel log for errors:

sudo dmesg | grep -i nvidia

Fix: Reboot first — DKMS sometimes needs a fresh boot to finish compiling modules. If still failing, reinstall headers and trigger a DKMS rebuild:

sudo apt install --reinstall linux-headers-$(uname -r)
sudo dkms autoinstall
sudo reboot

2. nvcc: command not found After NVIDIA Repo Install

Your PATH doesn’t include CUDA’s binary directory.

Fix: Re-apply the environment variable configuration:

source /etc/profile.d/cuda.sh

If /etc/profile.d/cuda.sh doesn’t exist, run Step 6 above to create it, then log out and back in.

3. Black Screen After Driver Installation

Nouveau is still loaded and conflicting with the NVIDIA driver.

Fix: Boot into recovery mode, then re-apply the blacklist and rebuild initramfs:

echo "blacklist nouveau" | sudo tee /etc/modprobe.d/blacklist-nouveau.conf
sudo update-initramfs -u
sudo reboot

4. GPG Error or Signature Verification Failure on apt update

The NVIDIA GPG key import failed or is corrupted.

Fix: Remove and re-import the key:

sudo rm -f /usr/share/keyrings/nvidia-cuda.gpg
curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/debian13/x86_64/8793F200.pub | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-cuda.gpg
sudo apt update

5. DKMS Build Failure During Driver Install

Missing or mismatched kernel headers prevent the NVIDIA module from compiling.

Fix: Install the exact headers for your running kernel and retry:

sudo apt install linux-headers-$(uname -r) build-essential
sudo apt install --reinstall nvidia-driver
sudo reboot

If you recently upgraded your kernel but haven’t rebooted yet, $(uname -r) reflects the old kernel. Reboot first, then run the fix commands.

Congratulations! You have successfully installed CUDA. Thanks for using this tutorial for installing the latest version of Nvidia CUDA on Debian 13 “Trixie”. 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 a dedicated and highly skilled Linux Systems Administrator with over a decade of progressive experience in designing, deploying, and maintaining enterprise-grade Linux infrastructure. His professional journey began in the telecommunications industry, where early exposure to Unix-based operating systems ignited a deep and enduring passion for open-source technologies and server administration.​ Throughout his career, r00t has demonstrated exceptional proficiency in managing large-scale Linux environments, overseeing more than 300 servers across development, staging, and production platforms while consistently achieving 99.9% system uptime. He holds advanced competencies in Red Hat Enterprise Linux (RHEL), Debian, and Ubuntu distributions, complemented by hands-on expertise in automation tools such as Ansible, Terraform, Bash scripting, and Python.
Back to top button