Ubuntu Nvidia driver驱动安装及卸载

下载官方驱动安装

1.安装驱动前一定要更新软件列表和安装必要软件、依赖(必须)

sudo apt-get update   #更新软件列表
 
sudo apt-get install g++
 
sudo apt-get install gcc
 
sudo apt-get install make

2.查看GPU型号(你自己知道显卡型号就不用查了,直接下一步;通用查看显卡型号命令:lspci | grep -i vga)

lspci | grep -i nvidia

得到如下输出,其中 GeForce GTX 1080 就是型号

01:00.0 VGA compatible controller: NVIDIA Corporation GP104 [GeForce GTX 1080] (rev a1)
01:00.1 Audio device: NVIDIA Corporation GP104 High Definition Audio Controller (rev a1)

3.官网下载对应驱动,注意要把 nvidia 驱动放在英文名文件夹下

https://www.nvidia.cn/Download/index.aspx?lang=cn

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

安装 NVIDIA 官方驱动

sudo chmod a+x NVIDIA-Linux-x86_64-418.126.02.run
sudo ./NVIDIA-Linux-x86_64-418.126.02.run -no-x-check -no-nouveau-check -no-opengl-files

The distribution-provided pre-install script failed! Are you sure you want to continue?

每次安装都会出现如下提示,实际上pre-install固定会失败的,目的就是为了让你知道你自己在干嘛,选择 Continue installation


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?

DKMS注册内核模块,直接选择 No 继续


或者有时会出现如下提示,直接ok忽略即可,32位兼容的问题
Unable to find a suitable destination to install 32-bit compatibility libraries. Your system may not be set up for 32-bit compatibility. 32-bit compatibility files will not be installed; if you wish to install them, re-run the installation and set a valid directory with the --compat32-libdir option.


Nvidia's 32-bit compatibility libraries? 不安装32位驱动,选择 No

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 继续

安装完成后,执行命令:

nvidia-smi

出现 GPU 相关信息则表示安装驱动成功

正确卸载驱动以及查看是否卸载干净命令

如果安装完显卡驱动之后,发现有问题,需要卸载,用下面方法,一步步来。
方法一:
 
#先查看驱动以及版本安装情况,命令如下:
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

ubuntu18.04-22.04极简版安装驱动

sudo apt-get update   #更新软件列表
 
sudo apt-get install g++  #安装必要依赖
sudo apt-get install gcc
sudo apt-get install make
 
sudo apt-get remove --purge nvidia*  #卸载原有所有驱动(或者nviida-*)
 
sudo gedit /etc/modprobe.d/blacklist.conf   #禁用nouveau,末尾添加如下两行命令保存
blacklist nouveau   
options nouveau modeset=0
 
sudo update-initramfs –u   #更新
reboot   #重启电脑
lsmod | grep nouveau   #检查,输入之后无其他输出,成功,继续
# 如果失败,继续试一下上面详细版禁用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   #重启显示服务,完成
posted @ 2024-04-23 09:46  牛奔  阅读(266)  评论(0编辑  收藏  举报