How to Add Nvidia Drivers to Your Debian Installation

A photograph of an Nvidia graphics card on a desktop PC.

Installing the official Nvidia driver is one of the most confusing parts of maintaining a Linux machine. Every distro provides its own set of drivers, each with its own compatibility and performance issues. This article will show you how you can install the official Nvidia drivers for your Debian system.

Tip: some tips for you to get Wayland to work properly with Nvidia graphics cards.

Preparing Your System for Nvidia Drivers

The first step in installing Nvidia drivers in Debian is to check whether your system detects your graphics card properly. To do that, run the following command in your distro’s terminal:

lspci | grep -iE "3d|display|VGA"

This will print a line of text highlighting all the available graphics cards in your machine.

A terminal showing the available graphics cards in the current machine.

Run the following command:

sudo sed -i '/^deb \|^deb-src / s/$/ non-free contrib/' /etc/apt/sources.list

Tip: learn how you can manipulate text streams in the terminal by understanding the sed utility.

Update your distro’s repository listings:

sudo apt update && sudo apt -y upgrade

Installing the Drivers using apt

At this point, your Debian system can now look for proprietary packages through apt. To install the proprietary Nvidia driver, you need to first install your system’s kernel headers:

sudo apt install linux-headers-$(uname -r) nvidia-detect firmware-misc-nonfree

Run the “nvidia-detect” program to determine the Nvidia driver that’s appropriate to your machine:

A terminal showing the output of the nvidia-detect binary.

Obtain the driver that you need using apt. In my case, I will install the “nvidia-driver” package since it supports my GTX 1050 Ti card:

sudo apt install nvidia-driver

Reboot your system to load your new Nvidia driver, then run nvidia-smi to see if the driver is properly working.

A terminal showing the output of nvidia-smi.

Installing the Drivers using Official Nvidia Packages

Aside from using apt, you can also install the graphics driver for your card from Nvidia itself. This allows you to install the latest driver package for your hardware as soon as it comes out.

To start, run the following command to install all the prerequisites for the graphics driver:

sudo apt install gcc make acpid dkms dracut libglvnd0 libglvnd-dev libglvnd-core-dev libc-dev linux-headers-$(uname -r)

Remove any previous installation of the nvidia-driver package from Debian’s repositories, then reboot your system:

sudo apt purge "*nvidia*"
sudo reboot

Open a web browser, then navigate to Nvidia’s driver downloads page.

A screenshot showing the Nvidia driver downloads page.

Select the model-specific model for your graphics card, then select “Linux 64-bit” under the “Operating System” dropdown box.

A screenshot showing the operating system dropdown box for Linux support.

Click “Search” to load all the compatible drivers for your system, then select the one that you want to install. In my case, I will select “535.146.02” since it’s the most recent stable driver for my card.

A screenshot showing the latest stable driver for Nvidia cards.

Disabling the Open Source Nouveau Driver

Disable the nouveau graphics driver from your system’s bootloader. This will ensure that the kernel will not load the open-source driver if the official one is present:

sudo -s
echo "blacklist nouveau" >> /etc/modprobe.d/blacklist.conf

Open the GRUB configuration file using your favorite text editor:

sudo nano /etc/default/grub

Look for a line that starts with “GRUB_CMDLINE_LINUX_DEFAULT.”

A terminal showing the default GRUB configuration file.

Insert the “rd.driver.blacklist=nouveau” string after the “quiet” value.

A terminal highlighting the GRUB configuration option with a blacklist for the open source Nvidia driver.

Reload your GRUB configuration, then create a new initramfs image:

sudo update-grub
sudo cp /boot/initrd.img-$(uname -r) /boot/initrd.img-nouveau
sudo dracut -q --force /boot/initrd.img-$(uname -r) $(uname -r)

FYI: understand how bootloaders work by restoring GRUB in broken installations.

Installing the Official Nvidia Driver in Debian

Restart your system, then press the Down Arrow, then E on the GRUB boot menu:

A screenshot showing the default GRUB output for Debian 12.

This will bring up a window where you can change the boot parameters for the current session. Navigate to the line that starts with “linux” then add “3” to the end of it.

A screenshot highlighting the modified boot arguments for Debian Linux.

Press Ctrl + X to continue the boot process.

Provide your user details once the system loads its login prompt.

A screenshot showing the non-GUI login screen.

Switch to the root user by running sudo -s, then run the Nvidia driver binary:

chmod +x ~/Downloads/

Select “Yes” when the installer asks you about including “32-bit compatibility binaries,” “DKMS modules,” and running the “nvidia-xconfig” utility.

A screenshot showing the prompt for the nvidia-xconfig utility.

Note: On newer Nvidia drivers, it will ask if you want to rebuild your machine’s initramfs. Select “Rebuild initramfs” to load the Nvidia driver in your system’s boot image.

Reboot your system to load your new graphics driver:

Lastly, check whether your system is using the new graphics drivers by running nvidia-smi.

A terminal showing the output for nvidia-smi for a newer graphics driver.

Learning the process of installing an Nvidia driver in Debian is just the first step in tinkering with the internals of Linux. Understand how you can extract the most out of your machine by configuring its ZRAM cache.

Image credit: Christian Wiediger via Unsplash. All alterations and screenshots by Ramces Red.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Ramces Red

Ramces is a technology writer that lived with computers all his life. A prolific reader and a student of Anthropology, he is an eccentric character that writes articles about Linux and anything *nix.

Leave a Reply

Your email address will not be published. Required fields are marked *