Okay, let's look at how you can install CUDA Toolkit 12.1 on Debian 12, given that the default Debian repositories might offer an older version. The recommended approach is to use the official installers provided directly by NVIDIA.
You have two primary methods provided by NVIDIA for Linux installations:
- Using NVIDIA's
.deb Packages (Recommended when available for your specific OS): This method uses Debian's package manager (apt) and integrates better with the system. NVIDIA provides instructions to add their repository or download a local .deb file.
- Using the distribution-independent
.run file Installer: This is a self-contained installer script that works across many Linux distributions. It gives you more control but doesn't use the system's package manager for the CUDA toolkit itself.
Here’s a breakdown of the steps for each method:
Method 1: Using NVIDIA .deb Packages
This is generally the preferred method if NVIDIA provides .deb files specifically targeted for Debian 12.
- Go to the NVIDIA CUDA Toolkit Download Page: Navigate to the official CUDA Toolkit download archive or the main downloads page.
- Select Your Version: Choose CUDA Toolkit 12.1.
- Select Your Platform:
- Operating System: Linux
- Architecture: x86_64
- Distribution: Debian
- Version: Select 12 (If Debian 12 is explicitly listed).
- Installer Type: Choose either
deb (network) or deb (local). The network option is usually easier as it sets up NVIDIA's repository for future updates via apt. The local option involves downloading a large .deb file.
- Follow NVIDIA's Instructions: The download page will provide the exact commands you need to run. These typically involve:
- Prerequisites: Installing essential packages like
build-essential.
- Downloading and adding the repository key (for network deb).
- Adding the NVIDIA CUDA repository to your
apt sources.
- Updating the package list:
sudo apt-get update
- Installing the CUDA package:
sudo apt-get -y install cuda or a more specific package like cuda-toolkit-12-1. The instructions on the NVIDIA page will specify the correct command.
- Post-installation: Configure the required environment variables (
PATH and LD_LIBRARY_PATH) as detailed in the NVIDIA installation guide.
- Note: If Debian 12 is not explicitly listed on the NVIDIA download page, using the
.deb files for a closely related distribution like Ubuntu 22.04 might work, but it's not officially supported for Debian 12 and could potentially lead to dependency issues or instability. In this case, the .run file method is often considered safer.
Method 2: Using the .run file Installer
This method works reliably if specific Debian 12 .deb packages aren't available or if you prefer a self-contained installation. Users have reported success using this method on Debian 12.
- Go to the NVIDIA CUDA Toolkit Download Page: Visit the official CUDA Toolkit download archive or the main downloads page.
- Select Your Version: Choose CUDA Toolkit 12.1.
- Select Your Platform:
- Operating System: Linux
- Architecture: x86_64
- Distribution: Select "Distribution Independent" or look for a generic Linux option.
- Installer Type: Choose
runfile (local).
- Download the
.run file: Download the provided .run file. It will be a large file.
- Install Prerequisites: Ensure you have necessary development tools and kernel headers installed:
sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install linux-headers-$(uname -r) (Installs headers for your currently running kernel)
- Make the Installer Executable: Open a terminal, navigate to the directory where you downloaded the file, and run:
chmod +x cuda_<version>_linux.run (Replace <version> with the actual file name).
- Run the Installer: Execute the installer with root privileges:
sudo ./cuda_<version>_linux.run.
- Follow the Installer Prompts:
- Read and accept the license agreement.
- You will be asked whether to install the NVIDIA driver, the CUDA Toolkit, samples, etc.
- Driver: If you already have a compatible NVIDIA driver installed, you might choose not to install the driver bundled with the CUDA toolkit. If you don't have a driver or want the one tested with this toolkit version, select yes.
- CUDA Toolkit: Select yes.
- OpenGL Libraries: Consider unchecking the option to install NVIDIA's OpenGL libraries if you want to keep using your system's default Mesa OpenGL libraries, especially if you are not using the NVIDIA driver for your display. You can use the flag
--no-opengl-libs when running the installer.
- Choose the installation path (usually
/usr/local/cuda-12.1).
- Post-installation: Set up the mandatory environment variables (
PATH and LD_LIBRARY_PATH) by adding lines to your shell configuration file (like ~/.bashrc or ~/.zshrc). For example:
export PATH=/usr/local/cuda-12.1/bin${PATH:+:${PATH}}
Remember to source the file (e.g., ) or log out and back in for changes to take effect.
Verification:
After installation (using either method) and setting environment variables, you can verify the installation by:
- Checking the driver version:
nvidia-smi
- Checking the CUDA compiler version:
nvcc --version
- Compiling and running one of the CUDA samples if you installed them.
Choose the method that best suits your needs and comfort level. If NVIDIA explicitly supports Debian 12 with .deb packages, that's often smoother. Otherwise, the .run file is a reliable alternative.