Physical Server

Installing a Nvidia GPU Driver in Ubuntu OS

2024-12-12 06:41:23

This topic takes Ubuntu 20.04 as an example to describe how to install Nvidia GPU driver.

1.1 Disabling a Nouveau Driver

Disable the open source Nouveau driver to avoid conflict with Nvidia GPU driver.

cat >> /etc/modprobe.d/blacklist-nouveau.conf << EOF
blacklist nouveau
blacklist lbm-nouveau
options nouveau modeset=0
EOF

You can install the driver either using the deb package in Section 2 or the run file in Section 3.

It should be noted that the Nvidia GPU driver must be installed in a non-desktop environment. In a desktop environment, you can run the systemctl set-default multi-user.target command and then restart to switch to the virtual terminal interface. Then, you can run the systemctl set-default graphical.target command and then restart to switch to the desktop environment.

1.2 Installing Driver Using deb Package (Or Using the Run File in 1.3)

1.2.1 Downloading a Driver

Visit:

https://www.nvidia.cn/content/DriverDownloads/confirmation.php?url=/tesla/470.129.06/nvidia-driver-local-repo-ubuntu2004-470.129.06_1.0-1_amd64.deb&lang=cn&type=Tesla

Click Agree and Start Downloading to download the driver                                               

or directly download the driver at the link below.

https://cn.download.nvidia.com/tesla/470.129.06/nvidia-driver-local-repo-ubuntu2004-470.129.06_1.0-1_amd64.deb

1.2.2 Installing a Driver

Assuming that the downloaded driver has been placed in /root/nvidia-driver-local-repo-ubuntu2004-470.129.06_1.0-1_amd64.deb. Install the Nvidia GPU driver by running the following command.

cat > /etc/apt/preferences.d/nvidia <<EOF
Package: *
Pin: release o=NVIDIA
Pin-Priority: 550
EOF
dpkg -i /root/nvidia-driver-local-repo-ubuntu2004-470.129.06_1.0-1_amd64.deb
apt-key --keyring /usr/share/keyrings/nvidia-driver-local-D9CB5EF8-keyring.gpg add /var/nvidia-driver-local-repo-ubuntu2004-470.129.06/D9CB5EF8.pub
apt-get update
apt-get install -y cuda-drivers
apt-get purge -y nvidia-driver-local-repo-ubuntu2004-470.129.06
apt-key --keyring /usr/share/keyrings/nvidia-driver-local-D9CB5EF8-keyring.gpg del D9CB5EF8rm -vf /etc/apt/preferences.d/nvidia

1.3 Installing a Driver Using Run File (Or Using the deb Package in 1.2)

1.3.1 Downloading a Driver

Download the driver at the link below:

https://download.nvidia.com/XFree86/Linux-x86_64/470.129.06/NVIDIA-Linux-x86_64-470.129.06.run

1.3.2 Installing a Driver

Assume that the downloaded driver is placed in /root/NVIDIA-Linux-x86_64-470.129.06.run

apt -y install build-essential #add necessary dependency chmod +x /root/NVIDIA-Linux-x86_64-470.129.06.run
/root/NVIDIA-Linux-x86_64-470.129.06.run

1.3.3 Verifying Whether the Driver is Normally Installed

nvidia-smi

The following interface displays when the driver is successfully installed.

PKx0Fcdh6HyM