[Record] Install nvidia graphics card driver on ubuntu20.04

For the newly installed Ubuntu20.04 system, if you want to learn about artificial intelligence, you need to configure a series of environments. Here I record the specific installation process.

Nvidia Graphics Driver Installation

1 Need to install dependencies before installation (must be executed)
sudo apt-get update #更新软件列表
#安装编译依赖
sudo apt-get install g++
sudo apt-get install gcc
sudo apt-get install make
2 Check your own GPU model. If you know this, it is not necessary. If you are not sure, you can use the following command to check
lspci | grep -Ei '(vga|display)' 
或者 
lspci | grep -i nvidia 
或者 
lspci | grep -i vga
3 Download the corresponding driver from Nvidia official website

Enter the official website
to download and open the page, just choose according to your own GPU model and system. I am an Ubuntu system, so choose Linux 64-bit to
insert image description here
download and get the xxx.run file (such as: NVIDIA-Linux-x86_64-515.65.01 .run), pay attention not to have Chinese in the storage path

4 Before installing the driver, delete the previously installed content related to Nvidia
sudo apt-get remove --purge nvidia*
5 disable nouveau

First of all, it is clear: nouveau is a universal driver. Before installing the NVIDIA driver, you need to disable the system’s own graphics card driver nouveau: you can first pass the command:

lsmod | grep nouveau

Check the enabling status of the nouveau driver. If there is output, it means that the nouveau driver is working. If there is no content output, it means that nouveau has been disabled.
If the nouveau driver has not been disabled, it needs to be further disabled

sudo gedit /etc/modprobe.d/blacklist.conf   
# 或者(blacklist-nouveau.conf)

Add the following at the end of the opened blacklist.conf, save the text and close

blacklist nouveau
options nouveau modeset=0
6 Enter the following content in the terminal to update, and restart the computer after the update (required)
sudo update-initramfs -u
# 然后电脑重启系统
sudo reboot

Check again whether nouveau has been disabled, no output indicates that it has been disabled

lsmod | grep nouveau
7 Install lightdm (Ubuntu20 and above can not be installed)

This step can also be done without installing lightdm, and using the gdm3 display manager that comes with ubuntu20.04 and 22.04. The intuitive difference is that the login window of gdm3 is in the middle of the display, while the login window of lightdm is on the left side. There is no difference in normal use. Other differences are not explored here;
if you want to install, you can enter the following command:

sudo apt-get install lightdm

(It should be noted that if you need to control multiple screens, gdm3 may be more suitable for you. If you use lightdm to set up multiple screens, there may be screen freezes, crashes, and inability to move, for reference only)

8. Stop the current display server and prepare to install the driver

In order to install new Nvidia drivers, the current display server needs to be stopped. The easiest way is to change to runlevel 3 using the telinit command. After entering the following linux command in the terminal, the display server will stop.
(If you can’t get in, press Ctrl + Alt + one of F2~F6 (corresponding to tty2~tty6 respectively)) (required)

sudo telinit 3

Then the following command line pops up:
insert image description here

In the text interface, disable the X-window service, enter in the terminal (required)
(if it is the default gdm3 display manager, the command is sudo /etc/init.d/gdm3 stop)

sudo /etc/init.d/gdm3 stop
或者
sudo /etc/init.d/lightdm stop
或者
sudo service lightdm stop
9 Install the CUDA driver

Introduction to the parameters of the second command:
–no-opengl-files Only install the driver files, not the OpenGL files. I personally tested this parameter without adding it to the desktop computer, and it is no problem. If it is not added to the notebook, there may be a loop login, that is, loop login.

sudo chmod 777 NVIDIA-Linux-x86_64-*.run   #给你下载的驱动赋予可执行权限,才可以安装
sudo ./NVIDIA-Linux-x86_64-*.run –no-opengl-files   #安装

insert image description here
All the way to the default
insert image description here
insert image description here

10 After the installation is complete, restart the interface display service

After the installation is complete, enter sudo service lightdm start or sudo service gdm3 start to restart the x-window service, and you will automatically enter the login interface.
If not, enter sudo reboot to restart.
If it doesn't work after restarting, try to remove the secure boot setting in the bios and change it to secure boot: disable
insert image description here

11 Open the terminal and enter nvidia-smi to see the figure below, indicating that the installation has been successful. The highest version of CUDA supported by the installed driver is 11.7, that is, the installed version of CUDA cannot exceed 11.7.

insert image description here
[The above is the process of installing the Nvidia graphics card driver. I am a little sleepy. Let’s take a rest first. I will continue to record the installation of CUDA and cuDNN tomorrow]

Guess you like

Origin blog.csdn.net/qq_29750461/article/details/128348569