How to Clean Install NVIDIA Drivers on Debian 11

How to Clean Install NVIDIA Drivers on Debian 11

Looking for a way to clean install NVIDIA drivers on Debian 11? This tutorial shows you the full process.

Many new Linux users get confused about graphics drivers. Unlike Windows, it’s more complex on Linux. And let’s face it, if you’re a gamer or a graphic designer, you need those drivers. Installing NVIDIA drivers and dealing with drivers on Linux, in general, can be tedious. 

This guide will make this process pretty easy. We will walk you through the required steps to clean install NVIDIA drivers on Debian 11. 

Let’s get started.

Uninstall Official NVIDIA Drivers from Debian 11

Since this will be a clean install, you must remove any NVIDIA drivers you installed previously. This step is necessary only if you have the drivers in your system. If you just freshly installed Debian or you don’t have any graphics drivers currently, you can move on to the next step.

Open your terminal and update the system with this command:

$ sudo apt update

Output:

sudo apt update debian

Now you can remove the existing NVIDIA drives completely from your device. To do that, run the following command:

$ sudo apt remove --purge nvidia-*

Output:

remove nvidia drivers from debian

In our case, we didn’t have any NVIDIA drivers installed, so nothing was removed. If you have the drivers, press Y to confirm the uninstallation.

You may also remove the dependency packages of the official NVIDIA drivers. Use the below command:

$ sudo apt autoremove --purge

Output:

remove nvidia drivers from debian

You can also try and clean any remaining cached NVIDIA driver packages. For that, use this command:

$ sudo apt clean

Output:

remove nvidia drivers from debian

Next, you need to reboot your device so that the changes take effect. Reboot your system with this command:

$ sudo reboot

One way to check whether the uninstallation was successful is by checking the current graphics drivers in use. To do so, run the following command:

$ lsmod | grep nvidia

Output:

check nvidia driver on debian

You’re not supposed to get any output, just like the screenshot above.

Install NVIDIA Drivers From the Debian Repository

After you’ve removed all the NVIDIA drivers from your device, it’s time to install the new ones. 

First, let’s check if your device has an NVIDIA GPU installed in it. You can check this with this command:

$ lspci | egrep 'VGA|NVIDIA'

Output:

check nvidia driver on debian

We’re just using a fresh Debian on a Virtual Machine. So your output will vastly differ from ours. And since you’re here, you should already have an NVIDIA GPU installed. Just check the version after running the above command.

When you’re done checking, move on to the installation process.

Enable contrib and non-free Repositories

We must add these two repositories to our source list since these contain the NVIDIA driver packages. To add the ‘contrib’ repo, run this command:

$ sudo apt-add-repository contrib

Output:

add nvidia driver repos on debian

It should be added. After that, add the ‘non-free’ repo using this command:

$ sudo apt-add-repository non-free

Output:

add nvidia driver repos on debian

Both repositories have been added to the list. Now let’s update the source list like before. Run this command:

$ sudo apt update

Output:

sudo apt update

The package repository cache has been successfully updated.

Install the Drivers

Now that we have the required repos, we can install the NVIDIA drivers. Install them by running this command:

$  sudo apt install nvidia-driver

Output:

clean install nvidia drivers on debian 11

When prompted for confirmation, press ‘Y’ to confirm. It’s a big package, so it will take a while to fully download and install the necessary packages. Till it’s finished, wait patiently. 

During the installation, you may face a window with a conflicting kernel module message. In that case, press OK to continue.

Once the installation is complete, reboot your device again with this command:

$ sudo reboot

Confirm the Installation 

To check if the drivers were installed correctly or not, go to ‘Activities’.

clean install nvidia drivers on debian 11

In the search bar, start typing ‘nvidia’. You should notice the NVIDIA X Server Settings app.

clean install nvidia drivers on debian 11

Run the app. If the app runs successfully, then the setup is successful. You can also check if the NVIDIA modules loaded correctly by running this command:

$ lsmod | grep nvidia 

Install NVIDIA Drivers From the Official Website

Another way of installing NVIDIA drivers is to download them from the official site and run the installation files. In this method, you will still need the contrib and non-free repositories. So add them by following that step.

Once added, install the Nvidia Detect utility by running this command:

$ sudo apt install nvidia-detect

Output:

nvidia detect on debian

You can use this tool to detect the NVIDIA GPU model you’re using. To do that, use this command:

$ sudo nvidia-detect

Output:

nvidia detect on debian

In your case, you should see the appropriate GPU model. You will also get some suggested driver series and driver package names.

Now you can head over to the NVIDIA drivers list page and download the correct driver for your system. 

download nvidia drivers on debian

Click on the link to take you to the download page.

download nvidia drivers on debian

Press the ‘Download’ button. You should see an agreement page like below:

download nvidia drivers on debian

To proceed, press ‘Agree & Download’. Choose the directory where you want to save the file.

The download should start.

While it’s being downloaded, you can install the driver prerequisites in the meantime. For that, use this command:

$ sudo apt -y install linux-headers-$(uname -r) build-essential libglvnd-dev pkg-config

If you have other graphics drivers(like nouveau) installed, you need to disable them first. So create a configuration file in nano. Use this command:

$ sudo nano /etc/modprobe.d/blacklist-nouveau.conf

Add these lines to the file:

blacklist nouveau
options nouveau modeset=0

Save and exit. Now run this command to rebuild the initramfs kernel:

$ sudo update-initramfs -u

Since you’ve disabled the default GPU drivers, you need to switch to CUI now. Enable multi-user login with CLI mode using this command:

$ systemctl set-default multi-user.target

Reboot your device after that. Login to your system as the root user. Let’s install the drivers now. Go to the right directory and run this command:

$ bash driver_file

Replace ‘driver_file’ with the corresponding name. Wait for it to complete.

While it’s being installed, you can set GUI as default again. Run this command:

$ systemctl set-default graphical.target

Finally, reboot your device with this command:

$ systemctl reboot

Final Thoughts

This guide shows you how to clean install NVIDIA Drivers on Debian 11. We’ve shown you how you can fully remove installed NVIDIA packages to make room for the latest ones. Then we walked you through the process of installing the drivers. If you followed this tutorial correctly, you should get ready to use the drivers by now.

If this guide helped you, please share it. 

Related Posts