Topics: How-to guide Graphics

Select NVIDIA driver packages manually

If you have an NVIDIA GPU, you can install official NVIDIA drivers as deb packages using the APT tool. This is useful in several cases:

  • You’re provisioning Ubuntu on multiple machines and you want to ensure the same driver configuration on all of them.

  • You’re running a custom kernel, so you need the DKMS driver.

  • The NVIDIA driver for your kernel version isn’t available yet, so you need the DKMS driver.

  • You want to learn how the drivers work on a lower level.

For most Ubuntu users, we recommend following the more automated Install NVIDIA drivers guide instead.

Warning

NVIDIA drivers installed from sources outside of those listed in this guide might potentially overwrite those provided by Ubuntu and might break Secure Boot.

We recommend installing the drivers provided by Ubuntu packages rather than downloading drivers from NVIDIA. The Ubuntu packages ensure that you install libraries compatible with your Ubuntu release.

Types of NVIDIA drivers

We package two types of NVIDIA drivers:

Unified Driver Architecture (UDA) drivers

These are recommended for the generic desktop use and gaming. They also support computing use cases such as AI and machine learning. You can also find them on the NVIDIA website.

Enterprise Ready Drivers (ERD)

These are recommended on servers and for computing tasks. These drivers come from an NVIDIA release branch that’s qualified and supported for longer on data center GPUs. They omit certain desktop-oriented features. Their packages can be recognized by the -server suffix. You can read more about these drivers in the NVIDIA documentation.

Additionally, Ubuntu provides the NVIDIA Fabric Manager and the NVIDIA Switch Configuration and Query (NSCQ) Library, which you will only need if you have NVswitch hardware. The Fabric Manager and NSCQ library are only available with the ERDs or -server driver versions.

Check driver versions

To check the version of your currently running driver:

$
cat /proc/driver/nvidia/version

Install the kernel modules

If your system uses Secure Boot (as most modern Intel and AMD systems do), your kernel will require the kernel modules to be signed. There are two mutually exclusive ways to achieve this:

Install the pre-compiled NVIDIA modules for your kernel

  1. Install the metapackage for your kernel flavor (e.g. generic, lowlatency, etc.), which is specific to the driver branch (e.g. 535) that you want to install, and whether you want the compute vs. general display driver (e.g. -server or not):

    $
    sudo apt install linux-modules-nvidia-${DRIVER_BRANCH}${SERVER}-${LINUX_FLAVOUR}

    For example, install linux-modules-nvidia-535-generic.

  2. Check that the modules for your specific kernel/ABI were installed by the metapackage:

    $
    sudo apt-cache policy linux-modules-nvidia-${DRIVER_BRANCH}${SERVER}-$(uname -r)

    For example:

    $
    sudo apt-cache policy linux-modules-nvidia-535-$(uname -r)
  3. If the modules were not installed for your current running kernel, upgrade to the latest kernel or install them by specifying the running kernel version:

    $
    sudo apt install linux-modules-nvidia-${DRIVER_BRANCH}${SERVER}-$(uname -r)

    For example:

    $
    sudo apt install linux-modules-nvidia-535-$(uname -r)

Build your own kernel modules using the NVIDIA DKMS package

By using the DKMS driver package, you can build the NVIDIA driver for the exact kernel that you’re running. This is useful when you’re using a custom kernel or when the standard NVIDIA packages are missing or lagging in release.

Warning

We don’t recommend using the DKMS modules unless you are running a custom kernel for which the prebuilt drivers are not supported. This is because the DKMS drivers are not signed with Canonical’s key and thus do not support Secure Boot.

The general procedure is to install the relevant NVIDIA DKMS package and linux-headers to build the kernel modules, and enroll your own key to sign the modules.

  1. Install the linux-headers metapackage for your kernel flavor (e.g. generic, lowlatency, etc.):

    $
    sudo apt install linux-headers-${LINUX_FLAVOUR}
  2. Check that the headers for your specific kernel were installed by the metapackage:

    $
    sudo apt-cache policy linux-headers-$(uname -r)
  3. If the headers for your current running kernel were not installed, install them by specifying the running kernel version:

    $
    sudo apt install linux-headers-$(uname -r)
  4. Install the NVIDIA DKMS package for your desired driver series:

    $
    sudo apt install nvidia-dkms-${DRIVER_BRANCH}${SERVER}

    This may automatically guide you through creating and enrolling a new key for Secure Boot.

    Alternatively, you can use ubuntu-drivers to automatically select an appropriate DKMS driver branch:

    $
    sudo ubuntu-drivers install --include-dkms

Install the user-space drivers and the driver libraries

After installing the correct kernel modules (see the relevant section of this document), install the correct driver metapackage:

$
sudo apt install nvidia-driver-${DRIVER_BRANCH}${SERVER}

(Optional) Install Fabric Manager and the NSCQ library

If your system comes with NVswitch hardware, then you will want to install Fabric Manager and the NVSwitch Configuration and Query library. You can do so by running the following:

$
sudo apt install nvidia-fabricmanager-${DRIVER_BRANCH} libnvidia-nscq-${DRIVER_BRANCH}

Note

While nvidia-fabricmanager and libnvidia-nscq do not have the same -server label in their name, they are really meant to match the -server drivers in the Ubuntu archive. For example, nvidia-fabricmanager-535 matches the nvidia-driver-535-server package version (not the nvidia-driver-535 package).

Switch between pre-compiled and DKMS modules

  1. Remove all existing NVIDIA packages from your system:

    $
    sudo apt --purge remove '*nvidia*${DRIVER_BRANCH}*'

    If you are unsure which ${DRIVER_BRANCH} to pick for removal, you might look at the installed nvidia packages and see the different ${DRIVER_BRANCH} numbers that are present on your system.

    Since autoremove will take care of all indirect dependencies, it is sufficient to list those that have been directly installed by using apt-mark.

    $
    apt-mark showmanual | grep nvidia
  2. Remove any additional packages that may have been installed as a dependency (e.g. the i386 libraries on amd64 systems) and which were not caught by the previous command:

    $
    sudo apt autoremove
  3. Install new drivers by following the earlier sections of this guide: Select NVIDIA driver packages manually.