Note: The environment I use is Ubuntu20.04, GTX1060
installation steps
1. Before installing the driver, be sure to update the software list and install the necessary software and dependencies
sudo apt-get update
#Update software listsudo apt-get install g++
sudo apt-get install gcc
sudo apt-get install make
2. Query hardware (graphics card) information
lspci | grep -Ei '(vga|display)'
or lspci | grep -i nvidia
orlspci | grep -i vga
3. Download the corresponding driver from the official website
Nvidia official website (https://www.nvidia.cn/)
Nvidia driver download address : https://www.nvidia.cn/Download/index.aspx?lang=cn
Enter the following interface and select the corresponding driver:
After downloading 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. Uninstall the original driver
NVIDIA graphics driver can delete the previously installed NVIDIA driver version through the following command and reinstall it.
sudo apt-get remove --purge nvidia*
5. Disable nouveau (nouveau is a generic driver)
Notice! Before installing the NVIDIA driver, you need to disable the system’s built-in graphics card driver nouveau: You can first lsmod | grep nouveau
check the enabling status of the nouveau driver through the command. If there is an output, it means that the nouveau driver is working. If there is no content output, it means that nouveau has been 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
Enter the following update in the terminal, and restart the computer after the update (required)
sudo update-initramfs -u
# 然后电脑重启系统
sudo reboot
After restarting, enter the following in the terminal, if there is no output, the shielding is successful
lsmod | grep nouveau
6. Install lightdm (optional, or not 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;
sudo apt-get install lightdm
7. Install the driver
-
Accessing the command line interface
In order to install the new Nvidia drivers, we need to stop the current display server. 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
-
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/lightdm stop或者(sudo service lightdm stop)
-
cd command to enter the directory where you store the driver
sudo chmod 777 NVIDIA-Linux-x86_64-515.65.01.run #给你下载的驱动赋予可执行权限,才可以安装 sudo ./NVIDIA-Linux-x86_64-515.65.01.run –no-opengl-files #安装
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. See what you need. (The desktop I installed did not encounter this situation) -
Some options during the installation of the graphics card driver (there are some problems that I can’t remember clearly, only the options that need to be selected are given:):
1.The distribution-provided pre-install script failed! Are you sure you want to continue? 选择continue installation 2.Would you like to register the kernel module souces with DKMS? This will allow DKMS to automatically build a new module, if you install a different kernel later? 选择 No 继续。 3.问题没记住, 选项是:install without signing 4.问题大概是:Nvidia's 32-bit compatibility libraries? 选择 No 继续。 5.Would you like to run the nvidia-xconfigutility to automatically update your x configuration so that the NVIDIA x driver will be used when you restart x? Any pre-existing x confile will be backed up. 选择 Yes 继续
8. Restart related services after the installation is complete
- After the installation is complete, enter
sudo service lightdm start
orsudo service gdm3 start
restart the x-window service, and you will automatically enter the login interface. If not, enter sudo reboot to restart, and then have a look.
(It doesn’t work after restarting, try to remove the secure boot setting in the bios and change it to secure boot: disable) - After the driver is installed, enter the terminal
nvidia-smi
to check whether it is installed, and if something like the following appears, it will be fine. The figure below shows that the highest version of CUDA supported by the installed driver is 11.7 ( note that the computer needs to be restarted here ).
- You can also enter to call
nvidia-settings
up the setting interface, and it will be OK.
Summarize:
sudo apt-get update #更新软件列表
sudo apt-get install g++ #安装必要依赖
sudo apt-get install gcc
sudo apt-get install make
sudo gedit /etc/modprobe.d/blacklist.conf #禁用nouveau,末尾添加如下两行命令保存
blacklist nouveau
options nouveau modeset=0
sudo update-initramfs -u #更新
reboot #重启电脑
lsmod | grep nouveau #检查,输入之后无输出,成功,继续
sudo telinit 3 #进入文本界面
sudo service gdm3 stop #停止显示服务
sudo chmod 777 NVIDIA-Linux-x86_64-430.26.run #给你下载的驱动赋予可执行权限,才可以安装
sudo ./NVIDIA-Linux-x86_64-430.26.run #安装
sudo service gdm3 start #重启显示服务,完成
Supplement: ubuntu desktop management environment gdm3, KDM, lightdm
GDM(GNOME Display Manager)
LightDM(Light Display Manager)
KDM(KDE Display Manager)
gdm3, kdm and lightdm are display managers. They provide graphical login and handle user authentication.
-
gdm3 is the successor of gdm, the GNOME display manager. The updated gdm3 uses a minimal version of gnome-shell and provides the same look and feel as a GNOME3 session.
# 安装: sudo apt-get install gdm3 sudo apt-get install gdm # 删除: sudo apt-get remove gdm3
-
LightDM is the canonical solution for display managers. It's supposed to be lightweight, and it's Ubuntu by default. Xubuntu and Lubuntu. It is configurable and there are various welcome themes available.
# 安装: sudo apt-get install lightdm # 删除: sudo apt-get remove lightdm
-
kdm is the display for the kde manager. But in KDE5, it was deprecated as SDDM, which is more suitable as a display manager, so by default, it is on screen.
# 安装: sudo apt-get install sddm # 删除: sudo apt-get remove sddm
Check: To check which display manager is currently in use, run the following command:
cat /etc/X11/default-display-manager
Switching: If you have more than one display manager installed, you can choose between them using the following method.
( Note: You must reboot for the changes to take effect. ):
sudo dpkg-reconfigure NAME
# Name可以是已安装的任意显示管理器, 如gdm3
例如: sudo dpkg-reconfigure gdm3
# 重启后生效
sudo reboot
Close: sudo service gdm3 stop
: Close the gdm3 service
Open: sudo service gdm3 start
: You can enter the login interface automatically
Reference blog:
Ubuntu20.04, 22.04 install nvidia graphics driver : https://blog.csdn.net/xianrenli38/article/details/125254853