How to Install Nvidia Drivers in Linux

How to Install Nvidia Drivers in Linux

The NVIDIA Driver is a software that enables communication between your Linux operating system and the NVIDIA GPU hardware.

The open-source Nouveau driver is preinstalled on Linux. Installing Nvidia driver benefits more features such as compatibility with video card hardware.

Prerequisites to Install Nvidia Drivers in Linux

Before installing Nvidia Drivers in Linux, make sure your system is meeting below specifications:

  • A Server running Linux VPS.
  • A non-root user with sudo privileges.
  • An Nvidia GPU.

Preparing to Install Nvidia Driver on Linux

Before beginning, you can check whether your computer has an NVIDIA GPU installed and check which NVIDIA GPU drivers are being used on your Linux system.

You can only install the Nvidia driver if your computer is equipped with an Nvidia GPU. To learn more about your GPU, type:

hwinfo --gfxcard --short

OR

sudo lshw -C display

The first step you should take after installing Ubuntu Desktop if your machine is equipped with an NVIDIA GPU is to install the NVIDIA GPU drivers.

To Find out whether NVIDIA GPU is installed on your system, run:

$ lspci | grep VGA

In the output, you can see which NVIDIA is installed on your system.

Linux systems use the open-source Nouveau drivers by default for NVIDIA graphics cards.

The proprietary NVIDIA drivers are not being used until you install them.

Run the command below to check if your Linux system is using the open-source Nouveau drivers:

$ lsmod | grep nouveau

To check if Nvidia drivers are installed, run the command below to see whether the proprietary NVIDIA drivers are shown in the output.

On Ubuntu, you can start using it after searching the NVIDIA X Server Settings app in the Application Menu of your Ubuntu desktop:

$ lsmod | grep nvidia

Methods to Install Nvidia Drivers on Ubuntu and Debian

There are 4 quick ways to Install Nvidia Drivers on Debian and Ubuntu:

  1. Command Line
  2. GUI
  3. PPA Repository
  4. Official nvidia.com package

You can skip to your preferred solution or review all of them to check which one is better for you according to your Linux knowledge and system equipment.

Note: You are recommended to use only one method. When you select your final method, do not try other commands.

Using Command Line to Install Nvidia Drivers on Ubuntu/Debian

Terminal adherents can use this method to install Nvidia on Ubuntu. Just follow the below steps to Install Nvidia Driver via Command Line.

First, you need to search for Nvidia drivers.

To do this, press Ctrl+Alt+T/ type ”terminal” in the Application menu to open the Terminal and run the command below:

apt search nvidia-driver

A list of your GPU’s available drivers is displayed in the output. Also, you can run the following command to search the package:

apt-cache search nvidia-driver

NVIDIA drivers are provided in the official non-free and contrib repository for Debian.

Conversely, the official non-free and contrib package repositories in Debian are not enabled by default.

Initially, use the following command to enable them:

sudo apt-add-repository contrib
sudo apt-add-repository non-free

As always, you will continue with updating your system package repository. Run the following command to do this before installing the driver:

sudo apt update
sudo apt upgrade

Now, you are ready to install your considered Driver according to your GPU. From the list of available GPU drivers, select one to install.

Usually, the latest tested proprietary version can be the right choice. Here is the syntax for installing a driver:

sudo apt install [driver_name]

The necessary packages will all be downloaded and installed. It will take some time to finish.

So once the right driver is installed on your Ubuntu system, use the following command to reboot it:

sudo reboot

As a verification, you can use the command below to view GPU information and the process which are using Nvidia GPU.

nvidia-smi

Using GUI to Install Nvidia Drivers on Linux Ubuntu

Ubuntu ships out of the box with open-source Nouveau drivers for Nvidia GPUs.

The Nouveau driver sometimes underutilizes the GPU’s potential and makes the system unstable or performs poorly.

Exclusive Nvidia drivers are far more dependable and stable.

Using the GUI Software & Updates program is the primary method for installing Nvidia drivers.

Let’s go through the below steps to check out the way you can Install Nvidia Drivers on Ubuntu via GUI:

  • On the App Menu, type ”Software and Updates” and open it.
  • Click on the Settings button.

how to use Ubuntu software updater

  • Click the Additional Drivers Tab and wait for the application to download a list of any new GPU drivers that are available.

Install Nvidia Drivers on Ubuntu via GUI

Your computer’s driver that is currently installed is the default choice. Usually, an open-source Nouveau display driver.

  • Here is where you can choose a driver. To do this, choose the most recent Nvidia driver with the designation “proprietary, tested” from the list.

This is the most recent stable driver for your GPU that Nvidia has released.

Choose the latest Nvidia driver on Ubuntu

Enter your password and watch for the installation to be completed, after clicking on Apply Changes As you see above.

You can also use the below commands to do this:

sudo shutdown -r now

OR

sudo reboot

In this way, the Nvidia drivers will be used on the next time boot up.

Using PPA Repository to Install Nvidia Drivers on Ubuntu

Software that is not offered in the official Ubuntu repositories can be distributed by developers thanks to the PPA repository.

This implies that installing the most recent beta drivers comes with the risk of a system that is unstable.

Follow these procedures to install the most recent Nvidia drivers via the PPA repository:

  • First, you need to add the PPA GPU repository to your Ubuntu system. To do this, run:
sudo add-apt-repository ppa:graphics-drivers/ppa

When prompted to add the repository, enter your password and press Enter.

  • Once the graphics drivers repository is added, it is time to verify the model of the GPU and view all available drivers.
  • To do this, use the command below to identify your current GPU model and view a list of available drivers for that GPU:
ubuntu-drivers devices
  • Now that you have detected which GPU model you are using, you are ready to install the Nvidia driver. The syntax of installing a specific driver is something like below:
sudo apt install [driver_name]

Also, you can use the following command to install recommended drivers automatically:

sudo ubuntu-drivers autoinstall

If you see no changes on your output, it means that the recommended driver has been already installed.

  • For the modifications to take effect, restart the computer.

Using Official nvidia.com package to Install Nvidia Driver on Debian

From the official Nvidia.com website, get the suggested Nvidia source package. Find a package name that corresponds with the driver’s number.

How to Download Nvidia Drivers

In your home directory, save the downloaded file.

To install Nvidia driver compilation prerequisites, run:

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

Use the command below to disable the default nouveau driver:

# echo blacklist nouveau > /etc/modprobe.d/blacklist-nvidia-nouveau.conf
# update-initramfs -u

To reboot to multi-user runlevel and disable the GUI user after reboot, type:

# systemctl set-default multi-user.target
# systemctl reboot

To install the Nvidia driver, login as root user and run:

# bash NVIDIA-Linux-x86_64-535.104.05.run

Run the following command to enable the system to boot into GUI:

# systemctl set-default graphical.target

Finally, reboot your Debian system:

# systemctl reboot

How to Install Nvidia Drivers on CentOS

Nvidia video graphic cards are supported by CentOS through the use of an open-source nouveau driver.

You can use the below steps to install the official Nvidia driver as a proprietary option in case the Nouveau driver is insufficient:

Run the command below to identify your Nvidia graphic card model:

#  lshw -numeric -C display

Based on your Linux operating system and Nvidia card model, you can use search parameters to get the Nvidia driver package from nvidia.com.

There is also the option to get the driver straight from the Nvidia Linux driver list if you are skilled in this area.

When everything is prepared, you need to have a file like the one below:

$ ls NVIDIA-Linux-x86_64-*

Run the commands below to install all compile prerequisites:

# yum groupinstall "Development Tools"
# yum install kernel-devel epel-release

Optional for installing dkms package, which guarantees the ongoing compilation and installation of Nvidia kernel modules in the event of a new kernel update:

# yum install dkms

Modify the configuration file located in /etc/default/grub to disable the nouveau driver. Nouveau.modeset=0 should be added to the line that begins with GRUB_CMDLINE_LINUX.

When you are finished, use the following command to apply the new GRUB configuration change:

BIOS:

$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg

EFI:

$ sudo grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg

Restart the Linux CentOS system. Verify that the nouveau open-source Nvidia driver is no longer in use when the boot is complete:

# lshw -numeric -C display

Now you can compare the results of the first time you used the above command with the output of the lshw command.

It is necessary to install the Nvidia drivers while the Xorg server is suspended. Change to text mode by running the command below:

# systemctl isolate multi-user.target

To install the Nvidia driver, type:

# bash NVIDIA-Linux-x86_64-*

When asked, select YES to install the NVIDIA 32-bit compatibility libraries and allow your X configuration file to update automatically.

That’s it! This should install the Nvidia driver on your CentOS Linux system. To further customize your Nvidia graphic card settings, restart your computer, log in, and run:

nvidia-settings

How to Install Nvidia Drivers on RHEL

The NVIDIA Driver communicates between Red Hat Enterprise Linux and your hardware, the NVIDIA Graphics GPU.

After stopping the GUI and disabling the nouveau driver through the GRUB boot menu, the NVIDIA drivers can be installed using the bash command.

$ lspci -vnn | grep VGA

Using search parameters determined by the model of your Nvidia card and the Linux operating system, download the Nvidia driver package from nvidia.com.

As an alternative, you can download the driver straight from the Nvidia Linux driver list.

$ ls NVIDIA-Linux-x86_64-*

Run the below commands to install all necessary dependencies for the compilation and installation of the Nvidia drivers.

# dnf groupinstall "Development Tools"
# dnf install elfutils-libelf-devel libglvnd-devel

Change the GRUB boot menu to permanently disable the nouveau driver and then reboot your system:

# grub2-editenv - set "$(grub2-editenv - list | grep kernelopts) nouveau.modeset=0"
# reboot

Use the following command to switch to the text mode:

#  systemctl isolate multi-user.target

To install the Nvidia driver, type:

# bash NVIDIA-Linux-x86_64-*

When asked, select YES to install NVIDIA’s 32-bit compatibility libraries, replace any pre-existing libglvnd files, and allow your X configuration file to update automatically.

Again, reboot your system:

# reboot

How to Install Nvidia Driver on Fedora

The Nvidia Driver can be installed on Fedora Manually and using RPM Fusion.

Install Nvidia Driver on Fedora via RPM Fusion:

Update your system before going through the installation process:

sudo dnf update

To identify your graphics card, run:

lspci -vnn | grep VGA

Use the following command to enable the RPM Fusion repository:

sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
sudo dnf install https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

Run the considered command to install the relevant drivers according to your graphic card and reboot your system when you are finished:

The most recent GeForce:

sudo dnf install akmod-nvidia

Legacy GeForce 400/500:

sudo dnf install xorg-x11-drv-nvidia-390xx akmod-nvidia-390xx

Legacy GeForce 8/9/200/300:

sudo dnf install xorg-x11-drv-nvidia-340xx akmod-nvidia-340xx

Then,

sudo reboot

Install Nvidia Driver on Fedora Manually:

To manually install Nvidia drivers on our PC, use the following command to identify your Nvidia graphics card:

lspci -vnn | grep VGA

Go to the official NVIDIA driver page and use the search parameters to get the drivers that are best compatible with your hardware.

If you are already aware of the drivers that your system requires, simply obtain the necessary driver package from the Nvidia Linux driver list.

The freshly downloaded drivers package will then be installed.

Use the commands below to install a few prerequisites that are necessary for the setup and compilation of Nvidia drivers on Fedora:

sudo dnf groupinstall "Development Tools"
sudo dnf install libglvnd-devel

Then, disable the nouveau driver by running the below command:

sudo grub2-editenv - set "$(sudo grub2-editenv - list | grep kernelopts) nouveau.modeset=0"

The above command will permanently disable the Nouveau driver and alter the GRUB boot menu.

To restart the system, type:

sudo reboot

The system can boot up without a graphical user interface. To access your system remotely, it is therefore advised that you enable an SSH server on your computer.

Use this command to transition from GUI mode to text mode so that you can install our drivers:

sudo systemctl isolate multi-user.target

Run the following command to install the drivers on your system and reboot your system when you are finished:

sudo bash NVIDIA-Linux-x86_64-* -y
sudo reboot

To get your system back into its normal state, type:

sudo systemctl restart systemd-logind

How to Install Nvidia Driver on Kali Linux

Follow the below steps to install Nvidia GPU drivers on Kali Linux, along with the CUDA toolkit

First, ensure your system is updated:

$ sudo apt update
$ sudo apt -y full-upgrade
$ sudo apt -y autoremove
$ reboot

To find out which video card you have installed and confirm that the nouveau open-source driver is being used by it, run:

$ lspci | grep -i vga

Run the command below to get information about the drivers installed.

$ lspci -s 00:02.0 -v

Note: 00:02.0 is the number from the previous output.

To install the drivers and CUDA toolkit, type the command below and reboot your system when you are finished:

$ sudo apt install nvidia-driver nvidia-cuda-toolkit
$ reboot

You can run a benchmark test with hashcat.

$ sudo apt install hashcat
$ hashcat -b | uniq

How to Configure NVIDIA Graphics Driver

The nvidia-settings command launches a GUI application for customizing the graphics driver from NVIDIA.

This can be used to configure numerous external screens or monitors that are attached to your system or to view all GPU information.

nvidia-settings

Starting it as follows will save your settings:

sudo nvidia-settings

Configure NVIDIA Graphics Driver

How to Change Drivers Using Terminal on Ubuntu

Ubuntu comes with a ubuntu-drivers command which allows users to manage binary drivers for Nvidia and other devices with a non-GUI method.

Follow the below steps to change drivers.

  • To view all driver packages (Apply on the current system), run:
sudo ubuntu-drivers list

In this way, all applied driver packages on the current system would be listed.

  • To show all enabled OEM packages, type:
sudo ubuntu-drivers list-oem

In this way, all OEM enablement packages that apply to your system will be displayed.

  • Regardless of Linux commands you can use to Get System and Hardware Information, the below command allows you to view all Nvidia hardware devices that require drivers and which software packages:
sudo ubuntu-drivers devices
  • To install a specific driver Nvidia version, you can use the following command and install it automatically:
sudo ubuntu-drivers install

How to Switch to the Nouveau Drivers

You can switch to the open-source Nouveau drivers if you’re experiencing issues with the proprietary NVIDIA drivers or if you simply no longer wish to use them.

For example on Ubuntu:

Open Ubuntu Desktop’s Software & Updates application from the Application Menu to switch to the open-source Nouveau drivers.

Using Software & Updates app to use Nouveau Drivers

Select the Using X.Org X server – Nouveau display driver from the list on the Additional Drivers tab and then click Apply Changes, as indicated in the image below.

Switch to the Nouveau Drivers

Once the Authentication Required page is opened, enter your password and click on Authenticate to log in.

Authentication Required page

After a successful login, the Software & Updates app will transition to the Nouveau open-source drivers. It’ll take a while to finish.

Switch to Nouveau drivers from Software & Updates app

The Software & Updates app should now switch to the Nouveau open-source drivers.

When you are finished, open the Terminal application, then restart your machine to make the changes effective:

$ sudo reboot

Certainly, the next time your computer boots, the open-source Nouveau drivers will be used.

How to Uninstall Nvidia Driver in Linux

Due to any reason, if you need to uninstall Nvidia driver, follow the below steps and simply stop using it on your Linux system:

On Ubuntu and Debian

First, you can start by viewing which packages are installed on your system Run the following command to see all installed packages:

$ sudo apt update
dpkg -l | grep -i nvidia

In this way, a list of all Nvidia packages on your system will be displayed.

Now, use the command below to uninstall Nvidia driver:

sudo apt-get remove --purge '^nvidia-.*'

After running the above command, all Nvidia packages will be purged from your system.

The official NVIDIA drivers’ dependent packages can also be removed. Use the command below:

Another option is to attempt clearing any remaining NVIDIA driver package cache. Use this command to do so:

$ sudo apt clean

Examining the graphics drivers that are currently in use is one method to determine if the uninstallation was effective. (Get No Output)

Use the following command to achieve this:

$ lsmod | grep nvidia

Since the ubuntu-desktop package is a dependency of the nvidia-common package, it might be purged too.

So, you can run the command below to reinstall the ubuntu-desktop package when you find it removed.

sudo apt-get install ubuntu-desktop

As you guessed, the last step is the restart recommendation. Run the following command to reboot the system:

sudo reboot

During boot, the system automatically loads the open-source Nouveau driver.

On CentOS

Run the command below to remove Nvidia Driver from your CentOS system:

sudo yum autoremove nvidia

Press Enter then type y to accept the remove.

On RHEL

Run the following command to remove the Nvidia Drivers altogether from RHEL:

sudo dnf remove nvidia-driver nvidia-settings cuda-driver kernel-devel-$(uname -r) kernel-headers-$(uname -r)

On Fedora

As you reviewed, there are two different ways to install Nvidia Driver on Fedora.

According to the method you have chosen to do this, use the related command to uninstall it.

Run the command below to remove all NVIDIA-related packages from your Fedora system if you used RPM Fusion:

sudo dnf erase nvidia

To uninstall Nvidia Drivers from Fedora after installing it Manually, type:

sudo ./NVIDIA-Linux-x86_64-418.56.run --uninstall

Keep in mind to replace the version number with the one you have installed.

On Kali Linux

Run the commands below to uninstall nvidia-driver on Kali Linux:

sudo apt remove nvidia-driver.
sudo apt autoclean && sudo apt autoremove

Why to Use Nvidia on Linux

Nvidia graphics processing units (GPUs) are used for gaming and business purposes in workplaces, data centers, visualization, the automobile industry, or artificial intelligence.

NVIDIA GPUs offer excellent performance and CUDA support. It provides stability and is used in deep learning and AI.

Also, NVIDIA’s broad driver support for well-known games is advantageous for Linux gamers.

Conclusion

Using this guide, you can also check if you have Nvidia GPU installed or not and find out the GPU drivers you are using on your Linux system.

This also helps all users with different knowledge levels and systems to Install Nvidia drivers on Ubuntu, Debian, CentOS, RHEL, Fedora, and Kali Linux

Changing drivers, Switching to the Nouveau drivers, Configuring the Nvidia graphics driver, and finally uninstalling Nvidia drivers were thought to present a complete guide for interested Linux users.

 

Leave a Reply

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