Ubuntu

How to Install the NVIDIA GPU Drivers on a Headless Ubuntu Server 22.04 LTS

NVIDIA GPUs are required even on headless (no graphical user interface installed) Ubuntu servers to encode/decode the media files, run the artificial intelligence codes, run the CUDA programs, and much more.

In this article, we will show you how to install the official NVIDIA GPU drivers on a headless Ubuntu Server 22.04 LTS machine.

Topic of Contents:

  1. Connecting to the Ubuntu Server 22.04 LTS via SSH
  2. Checking If the NVIDIA GPU Is Installed
  3. Updating the APT Package Repository Cache
  4. Available NVIDIA Drivers for Headless Ubuntu Server 22.04 LTS
  5. Installing the Latest Version of the NVIDIA Drivers on Ubuntu Server 22.04 LTS
  6. Checking If the NVIDIA Drivers Are Installed Correctly
  7. Conclusion
  8. References

Connecting to the Ubuntu Server 22.04 LTS Machine via SSH

Connecting to your Ubuntu Server 22.04 LTS machine via SSH is optional if you have access to the server hardware (where you installed the Ubuntu Server 22.04 LTS). You can just attach a mouse, a keyboard, and a monitor to the server and install the NVIDIA drivers on it.

If you don’t have access to the Ubuntu Server 22.04 LTS server hardware, you need to SSH into it to install the NVIDIA drivers.

To SSH into your Ubuntu Server 22.04 LTS machine, you can run the following command from a terminal app of your desktop/laptop from which you want to access the Ubuntu Server 22.04 LTS machine:

$ ssh <username>@<hostname/ip-address>

Make sure to replace the <username> and <hostname/ip-address> with the login username and domain name or the IP address of your Ubuntu Server 22.04 LTS machine, respectively.

If you’re using Windows 10 or Windows 11 and you need any assistance in connecting to your Ubuntu Server 22.04 LTS machine via SSH, read the article on How to SSH into the Linux Servers from Windows 10/11.

Checking If the NVIDIA GPU Is Installed

To check whether you have an NVIDIA GPU installed on your Ubuntu server machine, run the following command:

$ lspci | egrep -I 'vga|display|3d'

As you can see, we have an NVIDIA GeForce 1050 Ti GPU installed on our Ubuntu server machine.

Also, from the output of the following commands, you can see that the open-source nouveau drivers are used instead of the official NVIDIA GPU drivers. In the next sections, we will show you how to install the official NVIDIA GPU drivers on your Ubuntu server.

$ lsmod | grep nvidia

$ lsmod | grep nouveau

Updating the APT Package Repository Cache

Before you can install the official NVIDIA drivers on the Ubuntu servers, you should update the APT package repository cache with the following command:

$ sudo apt update

The APT package repository cache should be updated.

Available NVIDIA Drivers for Headless Ubuntu Server 22.04 LTS

You can install one of the two official NVIDIA drivers packages on a headless Ubuntu Server 22.04 LTS:

  1. nvidia-driver-[version]-server – Install this NVIDIA drivers package if you want to install the official NVIDIA drivers on your headless Ubuntu Server 22.04 LTS machine, including all the recommened packages and NVIDIA tools.
  2. nvidia-headless-[version]-server – Install this NVIDIA drivers package if you want to install only the required official NVIDIA drivers components and leave out all the recommended packages and NVIDIA tools to keep your Ubuntu server as lightweight as possible.

If you decide to install the nvidia-headless-[version]-server package to install the official NVIDIA drivers on your Ubuntu server, you may want to install one or both of the NVIDIA packages as well:

  1. nvidia-utils-[version]-server – Install this package if you need to run the nvidia-smi command to monitor the GPU usage on your Ubuntu server.
  2. libnvidia-encode-[version]-server – Install this package if you want to encode and decode the media on your Ubuntu server using the NVENC and NVDEC features of your NVIDIA GPU, respectively.

Here, <version> is the version number of the NVIDIA driver that you will install on your Ubuntu Server 22.04 LTS machine. At the time of this writing, you can install the NVIDIA driver version 418, 515, or 525 from the official package repository of Ubuntu. By the time you read this article, you may find the updated versions of the NVIDIA driver packages in the official package repository of Ubuntu. So, it’s always a good idea to check if an updated driver version is available before you install it. Also, make sure to install the same versions of all the NVIDIA driver packages. The version numbers of the NVIDIA drivers packages and the NVIDIA tools packages should match.

You can find the available versions of the nvidia-driver-<version>-server package with the following command:

$ sudo apt search '^nvidia-driver-[1-9]*-server$'

You can find the available versions of the nvidia-headless-<version>-server package with the following command:

$ sudo apt search '^nvidia-headless-[1-9]*-server$'

You can find the available versions of the nvidia-utils-<version>-server package with the following command:

$ sudo apt search 'nvidia-utils-[1-9]*-server'

You can find the available versions of the libnvidia-encode-<version>-server package with the following command:

$ sudo apt search 'libnvidia-encode-[1-9]*-server'

Installing the Latest Version of the NVIDIA Drivers on Ubuntu Server 22.04 LTS

To install the official NVIDIA drivers including all the recommended NVIDIA tools packages on your headless Ubuntu Server 22.04 LTS machine, run the following command:

$ sudo apt install nvidia-driver-525-server

To install the minimal version of the official NVIDIA drivers and the NVIDIA driver utilities on your headless Ubuntu Server 22.04 LTS machine, run the following command:

$ sudo apt install nvidia-headless-525-server nvidia-utils-525-server

To install the minimal version of official NVIDIA drivers, the NVIDIA driver utilities, and the NVIDIA NVENC encoder and NVDEC decoder libraries on your headless Ubuntu Server 22.04 LTS machine, run the following command:

$ sudo apt install nvidia-headless-525-server nvidia-utils-525-server libnvidia-encode-525-server

To confirm the installation, press Y and then press <Enter>.

The NVIDIA drivers packages and the required dependency packages are being downloaded. It takes a while to complete.

The NVIDIA drivers packages and the required dependency packages are being installed. It takes a while to complete.

Once you see the prompts, press <Tab> to select <OK> and press <Enter>.

The NVIDIA drivers should be installed on your headless Ubuntu Server 22.04 LTS machine.

For the changes to take effect, reboot your Ubuntu server with the following command:

$ sudo reboot

Checking If the NVIDIA Drivers Are Installed Correctly

Once your Ubuntu server boots, you can verify that the NVIDIA kernel modules are used instead of the open-source nouveau kernel modules with the following commands. So, the official NVIDIA GPU drivers are working just fine:

$ lsmod | grep nouveau

$ lsmod | grep nvidia

You can also find the usage information of your NVIDIA GPU using the nvidia-smi command. The output of this command also verifies that your NVIDIA GPU drivers are installed correctly.

$ nvidia-smi

Conclusion

We showed you how to check if you have an installed NVIDIA GPU on your Ubuntu Server 22.04 LTS machine. We also showed you how to install the official NVIDIA GPU drivers on the Ubuntu Server 22.04 LTS in headless mode (no graphical user interface installed) and how to verify if the official NVIDIA GPU drivers are working on Ubuntu Server 22.04 LTS.

References:

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.