NVIDIA drivers installation

This page shows how to install the NVIDIA drivers from the command line, using either the ubuntu-drivers tool (recommended), or APT.

NVIDIA drivers releases

We package two types of NVIDIA drivers:

  1. Unified Driver Architecture (UDA) drivers - which are recommended for the generic desktop use, and which you can also find on the NVIDIA website.

  2. Enterprise Ready Drivers (ERD) - which are recommended on servers and for computing tasks. Their packages can be recognised by the -server suffix. You can read more about these drivers in the NVIDIA documentation.

Additionally, we package 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

Manual driver installation (using APT)

Installing the NVIDIA driver manually means installing the correct kernel modules first, then installing the metapackage for the driver series.

Installing the kernel modules

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

Installing the pre-compiled NVIDIA modules for your kernel

Install the metapackage for your kernel flavour (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}

(e.g. linux-modules-nvidia-535-generic)

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)

(e.g. sudo apt-cache policy linux-modules-nvidia-535-$(uname -r))

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)

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

Building your own kernel modules using the NVIDIA DKMS package

Install the relevant NVIDIA DKMS package and linux-headers to build the kernel modules, and enroll your own key to sign the modules.

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

sudo apt install linux-headers-${LINUX_FLAVOUR}

Check that the headers for your specific kernel were installed by the metapackage:

sudo apt-cache policy linux-headers-$(uname -r)

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)

Finally, install the NVIDIA DKMS package for your desired driver series (this may automatically guide you through creating and enrolling a new key for Secure Boot):

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

Installing 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) Installing 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 will match the nvidia-driver-535-server package version (not the nvidia-driver-535 package).

Switching between pre-compiled and DKMS modules

  1. Uninstalling the NVIDIA drivers (below)

  2. Manual driver installation using APT

Uninstalling the NVIDIA drivers

Remove any 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`.

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

Transitional packages to new driver branches

When NVIDIA stops support on a driver branch, then Canonical will transition you to the next supported driver branch automatically if you try to install that driver branch.

See NVIDIA’s current support matrix in their documentation.

Troubleshooting

Driver/library version mismatch error

If you encounter the following error when running the nvidia-smi command:

Failed to initialize NVML: Driver/library version mismatch

This typically indicates that the userspace driver packages were upgraded while the kernel module is still on the older version (for example, the client reports one driver version while the kernel module reports another). This situation often occurs after a system upgrade. To verify this, check the kernel logs:

sudo dmesg

Look for error messages similar to:

NVRM: API mismatch: the client has the version 570.172.08, but
NVRM: this kernel module has the version 570.158.01.  Please
NVRM: make sure that this kernel module and all NVIDIA driver
NVRM: components have the same version.

Solution: Rebooting the system will load the updated kernel module and bring the versions back in sync.

No devices were found error

If you encounter the following error when running the nvidia-smi command:

No devices were found

This may occur if the open-source NVIDIA kernel driver nouveau is pre-installed and loaded, which conflicts with the proprietary NVIDIA driver. To check whether nouveau is loaded:

lsmod | grep nouveau

Solution: If nouveau kernel module is loaded, blacklist it and rebuild the initramfs:

echo "blacklist nouveau" | sudo tee /etc/modprobe.d/disable-nouveau.conf
echo "options nouveau modeset=0" | sudo tee -a /etc/modprobe.d/disable-nouveau.conf
sudo rmmod nouveau || true
sudo update-initramfs -u

Then reboot the system for the changes to take effect.