Make sure the system is up-to-date
This section is important to avoid pulling DKMS NVIDIA drivers during the installation.
First make sure your server is up-to-date:
If your system needs reboot, reboot it before running:
| |
Note: You can check if your system needs to be rebooted by checking if this file exists:
/var/run/reboot-required.
Rebooting before running apt autoremove allows apt to remove the kernel that was running before the reboot, which might be old and thus trigger the installation of DKMS NVIDIA drivers.
If you trust the automated way
Then the simplest way to install the NVIDIA drivers on Ubuntu is to use the built-in tool:
That’s it. Don’t install NVIDIA’s Debian repositories, no need to re-compile everytime a new kernel is released and it works with secure boot.
If you want to do it manually
First, identify the kernel flavor you are using:
- If you are running on a cloud,
${FLAVOR}should match the kernel you are running. For example, on AWS, users will probably be runninglinux-aws, the package to install should thus be...-server-aws(same for Azure, GCP…). If you are unsure about which kernel you are running, simply rununame -r. - If you are running the HWE kernel,
${FLAVOR}should begeneric-hwe-24.04(for Ubuntu 24.04). If you are unsure, check the output ofapt list --installed | grep linux-image, if you see-hwe-in the name, you are probably running the HWE kernel. - If you are in none of these cases,
${FLAVOR}is probablygeneric.
Then, simply install these two packages: the first contains the drivers and the second contains utilities like nvidia-smi.
Note:
servervs non-serverpackages: the server packages are for GPGPU (General Purpose GPU) usage, which is what you want for compute workloads. The non-server packages are for desktop usage (actually displaying graphics on a monitor).
If you don’t know which driver version to use, you can use 580 which is the latest version available in the archive as I write these lines.
Maintaining the drivers
To keep updating the NVIDIA drivers, regularly check if a new version of the drivers is available by running:
To avoid ever downloading the NVIDIA DKMS drivers during system updates, make sure to always update your kernel, reboot and run apt autoremove to remove old kernels that could trigger the installation of DKMS drivers. Indeed, new drivers are only pre-built for the latest kernels available in the Ubuntu archive
FAQ
Wait but isn’t that some opensource drivers that are less performant?
No. These will get you the closed-source, proprietary drivers.
But aren’t those old?
No. They might not be the latest ones if the latest ones just got released but they regularly get updated.
But what is the difference with the NVIDIA drivers from NVIDIA then?
- They are pre-compiled for your Ubuntu Kernel. The drivers you get from NVIDIA are DKMS packages, which mean they will be re-compiled everytime your kernel is updated. Which can take a lot of time.
- Drivers shipped by Canonical are signed by Canonical, so secure boot works.
So I don’t need to install the NVIDIA repo at all?
You might have to in some cases (for example to install the NVIDIA container toolkit).