How to Install Nvidia Drivers on Debian 12
From DigitalXS Documentation Project
For those aiming to optimize their graphics performance on Debian systems, installing Nvidia Drivers is a pivotal step. This guide will demonstrate how to install Nvidia Drivers on Debian 12 Bookworm or the older stable releases of Debian 11 Bullseye or Debian 10 Buster. By following this tutorial, users can choose between open-source variants or proprietary drivers, ensuring they harness the full potential of their graphics cards.
Nvidia Drivers offer a range of benefits:
- Enhanced Performance: Installing the correct driver can significantly boost the graphics performance, ensuring smoother visuals and better gameplay for gamers.
- Stability: Nvidia Drivers provide stability, reducing the chances of screen freezes, artifacts, or other graphical glitches.
- Frequent Updates: Nvidia regularly releases driver updates, addressing bugs and enhancing compatibility with the latest software and games.
- Choice of Installation: Users can install drivers from Debian’s repositories or directly from Nvidia, catering to individual preferences and system requirements.
- Support for Advanced Features: Nvidia Drivers unlock advanced graphics card features, enhancing the overall user experience, especially for video editing or 3D modeling tasks.
Pre-Installation Steps Before Nvidia Drivers Installation
Step 1: Update Debian System Packages
Before proceeding with the tutorial, ensuring your system is up-to-date with all existing packages is good.
sudo apt update
Proceed to upgrade any outdated packages using the following command.
sudo apt upgrade
Step 2: Previous Nvidia Installations From Debian (Situational)
When Nvidia drivers over the standard packages, it can result in unexpected issues, especially if you install the Nvidia drivers from Debian’s repository, then import the Nvidia Cuda repository and try to re-install or upgrade directly over those packages. If you use one method, stick to it, and if you want to swap, ensure you remove the previous installation to avoid conflicts.
Below I will briefly review some options for removing the previous Nvidia Drivers.
Example 1: Remove Previous Nvidia Drivers Installed via APT
First, use a blanket command to remove any traces of Nvidia installation on your system:
sudo apt autoremove nvidia* --purge
Example 2: Remove Previous Nvidia Drivers Installed via RUNFILE
The second method is for anyone that installed the Nvidia drivers using the “.run” file. To remove the runfile type of installation, use the following command:
sudo /usr/bin/nvidia-uninstall
Example 3: Remove Previous Nvidia Cuda Drivers Installed via RUNFILE
Lastly, remove the CUDA toolkit runfile installation using the following command.
sudo /usr/local/cuda-X.Y/bin/cuda-uninstall
These few methods may remove the Nvidia Drivers.
Enable Contrib and Non-Free Repositories on Debian 12, 11 or 10
The first task is enabling the “contrib” and “non-free” repositories to your Debian repositories. From Debian 12 Bookworm onwards, the command changes. Ensure you use the correct command matching your Debian distribution version.
First, make sure you have installed the following on your Debian system:
sudo apt install software-properties-common -y
Bookworm and onwards:
sudo add-apt-repository contrib non-free-firmware
Bullseye and Buster downwards:
sudo add-apt-repository contrib non-free
Once added, update your APT cache with the following command:
sudo apt update
Install Nvidia Drivers on Debian 12, 11, or 10 via DEFAULT APT
Step 1: Install Linux Kernel Headers
Before installing any Nvidia drivers, you will need to install the proper kernel headers for the NVIDIA driver to build with. You can install either 64bit or 32bit, and you can find this out by running the lscpu command:
lscpu | grep CPU
Example output:
CPU op-mode(s): 32-bit, 64-bit
CPU(s): 2
On-line CPU(s) list: 0,1
CPU family: 23
CPU MHz: 3900.025
NUMA node0 CPU(s): 0,1
From the output, the system is 64bit, so you need to install the following headers:
sudo apt install linux-headers-amd64
32-bit Debian systems, use the following command instead:
DO NOT USE THE BELOW COMMANDS IF YOU ARE ON A 64-BIT SYSTEM.
non-PAE kernel:
sudo apt install linux-headers-686
PAE kernel:
sudo apt install linux-headers-686-pae
Step 2: Install Nvidia Drivers via Debian’s Default Repository
Next, you can install the “nvidia-detect,” which will automatically suggest the best package for your graphics card.
To do this, use the following command:
sudo apt install nvidia-detect
With Nvidia-detect installed, execute the command to identify your current Nvidia Graphics Card:
nvidia-detect
The output reveals that the example machine features a GeForce GTX 1650 card and recommends installing the nvidia-driver package. However, this remains a suggestion.
Next, install the recommended package:
sudo apt install nvidia-driver linux-image-amd64
You will see a note about the free Nouveau graphics driver conflicting with the installed new driver. As per the message, you need to reboot to correct this; for now, press the “ENTER KEY” to proceed.
Step 3: Reboot and Confirm Installation
Once installed, reboot your system:
sudo reboot
Situational: Install Nvidia Legacy Drivers (For Older Cards)
If your Nvidia Graphics card is quite old from 400 Series downwards, you will need to install the legacy drivers. The process is the same, just with a new install command:
sudo apt install nvidia-legacy-390xx-driver firmware-misc-nonfree
Once complete, do not forget to reboot your system.
sudo reboot now
You can technically install the 340 series, but it no longer has support, and it contains several major security flaws. Although you might consider replacing 390xx with 340xx, Debian advises against it.
Install Nvidia Drivers on Debian 12, 11, or 10 via Nvidia APT PPA
The second method lets you install the latest drivers for your desktop or server from the Nvidia Cuda APT repository. I suggest you use these drivers because you’ll get updates immediately after their release. This approach benefits security and performance since Nvidia frequently releases updates. Now, you also have the option to install the open-source version.
Step 1: Identify Your Nvidia Graphics Card on Debian
If you have an older NVIDIA Graphics card, start by identifying it to ensure support. However, if you own a brand-new card, you can skip this part because your card undoubtedly has support.
Now, let’s identify your graphics card module:
lspci | grep -e VGA
Example output:
03:00.0 VGA compatible controller: NVIDIA Corporation TU117 [GeForce GTX 1650] (rev a1)
Step 2: Import Nvidia GPG Key on Debian
First, check if you have already installed the following packages by using this command:
sudo apt install dirmngr ca-certificates software-properties-common apt-transport-https dkms curl -y
Next, import the GPG key, and ensure you match the import to your distribution version.
Please leave a comment or send me a message via the contact form if the GPG import fails. Every so often, Debian can upgrade its GPG keys. This is rare, but it does occur; if it does, I’ll update the command.
Bookworm:
curl -fSsL https://developer.download.nvidia.com/compute/cuda/repos/debian12/x86_64/3bf863cc.pub | sudo gpg --dearmor | sudo tee /usr/share/keyrings/nvidia-drivers.gpg > /dev/null 2>&1
Bullseye:
curl -fSsL https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64/3bf863cc.pub | sudo gpg --dearmor | sudo tee /usr/share/keyrings/nvidia-drivers.gpg > /dev/null 2>&1
Buster:
curl -fSsL https://developer.download.nvidia.com/compute/cuda/repos/debian10/x86_64/3bf863cc.pub | sudo gpg --dearmor | sudo tee /usr/share/keyrings/nvidia-drivers.gpg > /dev/null 2>&1
Step 3: Import Nvidia APT Repository on Debian
Second, import the repository for your Debian system, and again ensure you import the correct one to match your Debian distribution version.
Bookworm:
echo 'deb [signed-by=/usr/share/keyrings/nvidia-drivers.gpg] https://developer.download.nvidia.com/compute/cuda/repos/debian12/x86_64/ /' | sudo tee /etc/apt/sources.list.d/nvidia-drivers.list
Bullseye:
echo 'deb [signed-by=/usr/share/keyrings/nvidia-drivers.gpg] https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64/ /' | sudo tee /etc/apt/sources.list.d/nvidia-drivers.list
Import Nvidia Repository for Debian 10 Buster:
echo 'deb [signed-by=/usr/share/keyrings/nvidia-drivers.gpg] https://developer.download.nvidia.com/compute/cuda/repos/debian10/x86_64/ /' | sudo tee /etc/apt/sources.list.d/nvidia-drivers.list
Step 4: Install Nvidia Drivers – Proprietary or Open-Source Options on Debian
Update your sources list to reflect the newly added repository.
sudo apt update
Next, install the latest NVIDIA drivers; below are some examples with and without CUDA and proprietary and open-source versions.
Option 1: Install NVIDIA Drivers Without Cuda Support (Proprietary):
sudo apt install nvidia-driver nvidia-smi nvidia-settings
Option 2: Install NVIDIA Drivers With Cuda Support (Proprietary):
sudo apt install nvidia-driver cuda nvidia-smi nvidia-settings
Option 3: Install NVIDIA Drivers Without Cuda Support (Opensource):
sudo apt install nvidia-driver nvidia-kernel-open-dkms nvidia-smi nvidia-settings
Option 4: Install NVIDIA Drivers With Cuda Support (Opensource):
sudo apt install nvidia-driver nvidia-kernel-open-dkms cuda nvidia-smi nvidia-settings
The download is large and can take a while; given this is a general release, it is recommended to install all the drivers to avoid any issues or inconsistencies on your Debian desktop.
One good thing about the Nvidia repository installation is that if you forgot to remove the previous one, you will see a prompt for users with pre-existing installations before the installation continues. Select Yes to remove any existing drivers. Failure to do this may cause system instability. Once done, the installation will be complete.
Step 4: Reboot
During the final phase of the installation, most users will typically see a message like the image below:
To activate the installation, reboot your system. You can use the following command after completing the installation:
sudo reboot
Situational: Install 32-bit Support for Nvidia Drivers on Debian
You can easily enable and install 32-bit support first. Install the 64-bit drivers mentioned earlier, and then follow these steps.
First, activate the 32-bit architecture using this command:
sudo dpkg --add-architecture i386
Update the APT-CACHE to reflect the changes to the architecture:
sudo apt update
Install 32-bit support, and remove the Cuda package “libcuda1-i386” for those users not requiring it.
sudo apt install libcuda1-i386 nvidia-driver-libs-i386
Reboot your PC:
sudo reboot
Confirm Nvidia Drivers Installation on Debian 12, 11 or 10
Step 1: Verify Nvidia Drivers Utilizing via CLI Command on Debian
First, verify the installation by running NVIDIA-SMI, as the manual installation steps showed beforehand.
nvidia-smi
If successful, you should see something similar too:
Step 2: Verify Nvidia Drivers Utilizing via GUI on Debian
Alternatively, you can open the GUI for desktop users using the following command:
nvidia-settings
Or open the application icon located in the following path:
Activities > Show Applications > Nvidia X Server
Here you should see a panel with all your Nvidia Driver settings available and system information. At this stage, for most, you have successfully installed the Nvidia Drivers of your choice on Debian.
Below are additional screenshots of the Nvidia Settings GUI Example Screenshots for users new to Linux and utilizing Nvidia Drivers:
Conclusion and Recap: Installing Nvidia Drivers on Debian
Throughout this guide, we’ve demonstrated the steps to install Nvidia drivers on Debian 12 Bookworm, Debian 11 Bullseye, and Debian 10 Buster. We covered the standard method using Debian’s default repository and the advanced approach of obtaining the latest drivers directly from Nvidia’s apt repository. Following this guide, users can optimize their Debian system’s graphics performance with the most suitable Nvidia driver option. We hope this tutorial proves valuable in enhancing your Debian computing experience.