前言
英伟达更新了安装驱动的方式,更新一下文档
旧文:Ubuntu Nvidia driver驱动安装及卸载
下载官方驱动安装
1.安装驱动前一定要更新软件列表和安装必要软件、依赖(必须)
sudo apt-get update #更新软件列表sudo apt-get install -y g++ gcc make
2.查看GPU型号(你自己知道显卡型号就不用查了,直接下一步;通用查看显卡型号命令:lspci | grep -i vga)
lspci | grep -i nvidia
得到如下输出,其中 Tesla T4
就是型号
00:06.0 3D controller: NVIDIA Corporation TU104GL [Tesla T4] (rev a1)
00:07.0 3D controller: NVIDIA Corporation TU104GL [Tesla T4] (rev a1)
3.官网下载对应驱动,注意要把 nvidia 驱动放在英文名文件夹下
https://www.nvidia.cn/drivers/lookup/
4.卸载原有驱动,请看下方「正确卸载驱动以及查看是否卸载干净命令」
5.禁用nouveau(nouveau是通用的驱动程序)(必须)
Ubuntu 系统集成的显卡驱动程序是 nouveau ,它是第三方为 NVIDIA 开发的开源驱动,我们需要先将其屏蔽再安装 NVIDIA 官方驱动,否则直接安全驱动的话往往会报以下错误:ERROR: The Nouveau kernel driver is currently in use by your system. This driver is incompatible with the NVIDIA driver
将 nouveau
驱动加入黑名单,将如下内容加入 /etc/modprobe.d/blacklist.conf
文件中:
sudo vim /etc/modprobe.d/blacklist.conf# 添加如下内容
blacklist vga16fb
blacklist nouveau
blacklist rivafb
blacklist rivatv
blacklist nvidiafb
然后执行命令
sudo update-initramfs -u
重启机器后(必须),执行如下命令,如果没有输出则证明禁用成功
sudo lsmod | grep nouveau
6.开始安装 NVIDIA 官方驱动
执行 dpkg -i
将本地仓库包安装到系统中
sudo dpkg -i nvidia-driver-local-repo-ubuntu2004-560.35.03_1.0-1_amd64.deb
输出
sudo dpkg -i nvidia-driver-local-repo-ubuntu2004-560.35.03_1.0-1_amd64.deb
Selecting previously unselected package nvidia-driver-local-repo-ubuntu2004-560.35.03.
(Reading database ... 114186 files and directories currently installed.)
Preparing to unpack nvidia-driver-local-repo-ubuntu2004-560.35.03_1.0-1_amd64.deb ...
Unpacking nvidia-driver-local-repo-ubuntu2004-560.35.03 (1.0-1) ...
Setting up nvidia-driver-local-repo-ubuntu2004-560.35.03 (1.0-1) ...The public nvidia-driver-local-repo-ubuntu2004-560.35.03 GPG key does not appear to be installed.
To install the key, run this command:
sudo cp /var/nvidia-driver-local-repo-ubuntu2004-560.35.03/nvidia-driver-local-63C60622-keyring.gpg /usr/share/keyrings/
此时复制授权密钥
sudo cp /var/nvidia-driver-local-repo-ubuntu2004-560.35.03/nvidia-driver-local-63C60622-keyring.gpg /usr/share/keyrings/
再次执行
sudo dpkg -i nvidia-driver-local-repo-ubuntu2004-560.35.03_1.0-1_amd64.deb
修复依赖关系(如果有问题):
sudo apt-get install -f
更新包列表
sudo apt-get update
搜索驱动 nvidia-driver-560,是否存在
sudo apt-cache search nvidia-driver-560
输出
nvidia-driver-530-open - Transitional package for nvidia-driver-560-open
nvidia-driver-530 - Transitional package for nvidia-driver-560
nvidia-driver-560-open - NVIDIA driver (open kernel) metapackage
nvidia-driver-560 - NVIDIA driver metapackage
nvidia-headless-560-open - NVIDIA headless metapackage (open kernel module)
nvidia-headless-560 - NVIDIA headless metapackage
nvidia-headless-no-dkms-560-open - NVIDIA headless metapackage - no DKMS (open kernel module)
nvidia-headless-no-dkms-560 - NVIDIA headless metapackage - no DKMS
xserver-xorg-video-nvidia-560 - NVIDIA binary Xorg driver
开始安装驱动
sudo apt-get install nvidia-driver-560
安装完成,最后执行 nvidia-smi
,有输出,表示安装成功!!
nvidia-smi
Wed Sep 4 10:06:18 2024
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 560.35.03 Driver Version: 560.35.03 CUDA Version: 12.6 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 Tesla T4 Off | 00000000:00:06.0 Off | 0 |
| N/A 62C P0 29W / 70W | 1MiB / 15360MiB | 5% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
| 1 Tesla T4 Off | 00000000:00:07.0 Off | 0 |
| N/A 67C P0 31W / 70W | 1MiB / 15360MiB | 5% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------++-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| No running processes found |
+-----------------------------------------------------------------------------------------+
正确卸载驱动以及查看是否卸载干净命令
如果安装完显卡驱动之后,发现有问题,需要卸载,用下面方法,一步步来。
方法一:#先查看驱动以及版本安装情况,命令如下:
ls /usr/src | grep nvidia#进入安装目录,用驱动自带卸载命令卸载,一般情况下能卸载干净
cd /usr/bin
ls nvidia-*
sudo nvidia-uninstall#然后用上面的查看命令查看是否卸载干净,完成卸载
ls /usr/src | grep nvidia#如果需要卸载干净所有英伟达驱动命令,如下
sudo apt-get remove --purge nvidia-*(/nvidia*)
sudo apt autoremove # 此命令在万般无奈之下在使用,可能会卸载无辜软件,影响稳定性。。。方法二:(推荐)#直接卸载驱动
sudo ./显卡驱动包名称 --uninstall#卸载两件套
sudo apt-get purge nvidia*
sudo apt-get autoremove
sudo reboot