How to Install Nvidia Driver on Debian 9 Stretch From Command Line

This tutorial will be showing you how to install Nvidia graphics driver on Debian 9 Stretch. Debian by default uses the open source nouveau driver, which is included in the Linux kernel, for Nvidia cards. However, this driver lacks 3D acceleration support. If you are a gamer or need to work with 3D graphics, then you will benefit from the better performance of the proprietary Nvidia driver.

Note: Before installing the proprietary driver, I recommend disabling secure boot if you are using UEFI firmware. The Nvidia module will be added into Linux kernel after you follow this tutorial, so the new kernel can not pass signature verification. If secure boot is enabled, your system could become unbootable.

Enable sudo for Standard User Account

Some commands in this tutorial are prefixed with sudo. If your user account isn’t in the sudoer list, you can use the following command to switch to root user, assuming you know the root password.

su -

If you want to add the standard user account into sudoer list, run the following command as root. Replace username with your actual username.

adduser username sudo

Then install sudo utility.

apt install sudo

Log out and log back in for the change to take effect. From now on, the standard user can use sudo to manage the system.

Installing Nvidia Driver on Debian 9 Stretch From Command Line

First, open up a terminal window and check which driver is being used for Nvidia card with the following command.

sudo apt install lshw

sudo lshw -c display

By default, the open source nouveau driver is being used for Nvidia card.

debian 9 check graphics driver

On my desktop computer, there’s no driver found, because my HDMI cable is connected to the Nvidia card, but the proprietary driver isn’t installed yet.

debian 9 display driver

Since the nvidia-driver package in Debian is proprietary, we need to enable contrib and non-free component in /etc/apt/sources.list file with the following commands. (You can also do it in Synaptic package manager, but using commands is easier and more convenient.)

sudo apt install software-properties-common
sudo add-apt-repository contrib
sudo add-apt-repository non-free

Then update software sources.

sudo apt update

Now install the nvidia-driver from the default repository.

sudo apt install nvidia-driver

During the installation, you will see the following message, simply press Enter to continue.

xserver-xorg-config-nvidia

If you encounter dependency problem while running the above command

the following packages have unmet dependencies

Then you need to install the driver from stretch-backports repository. First, add the repository with the following command.

sudo add-apt-repository 'deb http://ftp.debian.org/debian stretch-backports main contrib non-free'

Note that you need contrib and non-free component to install Nvidia driver. If you have previously added the stretch-backports repository, make sure the two components are added. Now update software sources.

sudo apt update

Install nvidia-driver package from stretch-backports repository.

sudo apt install -t stretch-backports nvidia-driver

Once the installation is complete, restart your computer.

sudo shutdown -r now

Check which drivers is being used for your Nvidia card.

sudo lshw -c display

As you can see, my computer is now using the proprietary Nvidia driver.

nvidia driver debian 9

Although the Nvidia driver is being used for Nvidia card, but your computer may still be using the integrated Intel graphic card.

Switch Between Intel and Nvidia Graphics Card on Desktop Computer

If you are using a desktop computer, you just need to shut down your computer, re-connect your HDMI cable to the Nvidia card, and start your computer. You can then start the Nvidia X Server Settings program from your application menu.

nvidia x server settings

Or from command line.

nvidia-settings

You can check the driver version, graphics card specification, card temperature and so on.

nvidia graphics driver debian stretch

Switch Between Intel and Nvidia Graphics Card on Nividia Optimus Laptops

If you are using a laptop computer with Nvidia Optimus card and try starting the Nividia X Server Settings program, you will see the following error.

you do not appear to be using the nvidia x driver debian

Sadly, after running the following commands

sudo apt install nvidia-xconfig

sudo nvidia-xconfig

My lightDM display manager won’t work after a reboot. Nvidia-xconfig is deprecated in Debian 9. It appears you can’t get the whole system to use Nvidia card, but you can use Bumblebee and Primus to run individual applications on Nvidia card.

To install Bumblebee and Primus, run the following commands:

sudo dpkg --add-architecture i386

sud apt update

sudo apt install bumblebee bumblebee-nvidia primus primus-libs:i386 libgl1-nvidia-glx:i386

Normally, the system uses Intel graphics card,

glxinfo | grep OpenGL

debian 9 switch intel graphics card

To run a program on Nividia card, simply prefix the command with primusrun.

primusrun glxinfo | grep OpenGL

As you can see, the glxinfo is now running on Nvidia card,

debian 9 nvidia bumblebee

To open the Nvidia X Server Settings program, run

optirun nvidia-settings -c :8

How to Uninstall the Proprietary Nvidia Driver on Debian 9 Stretch

If for some reason you don’t want the proprietary driver any more, you can remove it by running the following command.

sudo apt purge nvidia-*

sudo apt autoremove

I hope this tutorial helped you install Nvidia drivers on Debian 9 Stretch. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks. Take care 🙂

Rate this tutorial
[Total: 8 Average: 3.9]

6 Responses to “How to Install Nvidia Driver on Debian 9 Stretch From Command Line

  • Thank you so much! One of the best instructions I ever read, very helpful!!!

  • ahmadraniri
    5 years ago

    thanks sir…. I hope you get a great life….

  • Ananthakrishnan
    5 years ago

    Than you so much. I installed nvidia graphics driver using your shell commands and working nfine

  • Dave Harris
    5 years ago

    Thank you.

  • Marcelo Maciel
    5 years ago

    Thanks man! I am Brazilian and I found in your blog the best instructions to install nvidia driver in debian, much better than in brazilian sites! You have won a player

  • Owen Bradstreet
    5 years ago

    Worked perfectly, very easy to follow. Nice work!

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here