1 安装必要依赖
sudo apt-get update
sudo apt-get install g++
sudo apt-get install gcc
sudo apt-get install make
2 卸载原有的驱动
服务器可能会自带有驱动,需要先卸载干净
sudo apt-get remove nvidia-*
3 禁用 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。
3.1 打开配置文件
sudo vim /etc/modprobe.d/blacklist-nouveau.conf
3.2 向打开的文件中写入下面的内容:
blacklist nouveau
options nouveau modeset=0
3.3 更新系统
sudo update-initramfs -u
3.4 重启系统
reboot
3.5 验证是否禁用成功
lsmod | grep nouveau
4 安装Ubuntu驱动
4.1 查看可安装Ubuntu驱动列表
sudo ubuntu-drivers devices
4.2 安装指定驱动
选择带有“recommended”标记的驱动程序即可,更高版本的是最新版,可能存在兼容问题。
sudo apt-get install nvidia-driver-535
5 下载NVIDIA显卡驱动
5.1 查看显卡版本
lspci | grep -i vga
结果显示,我的显卡是是2080Ti,所以在NVIDIA官网选择:
5.2 把下载的文件传到服务器,在服务器中找执行如下指令:
sudo chmod a+x NVIDIA-Linux-x86_64-525.105.17.run
sudo ./NVIDIA-Linux-x86_64-525.105.17.run -no-opengl-files -no-x-check -no-nouveau-check
注:只有禁用opengl这样安装才不会出现循环登陆的问题
-no-x-check:安装驱动时关闭X服务
-no-nouveau-check:安装驱动时禁用nouveau
-no-opengl-files:只安装驱动文件,不安装OpenGL文件
6 安装过程遇到的选项
6.1 An alternate method of installing the NVIDIA driver was detected. (This is usually a package provided by your distributor.) A driver installed via that method may integrate better with your system than a driver installed by nvidia-installer. Please review the message provided by the maintainer of this alternate installation method and decide how to proceed:
选 【continue installation】
6.2 Install NVIDIA's 32-bit compatibility libraries?
选【No】
6.3 Would you like to run the nvidia-xconfig utility to aotumatically update your X configuration file so that the NVIDIA X driver will be used when you restart X?ANy pre-existing X configuration file will be backed up.
选【No】
6.4 Would you like to register the kernel module sources with DKMS? This will allow DKMS to automatically build a new module, if your kernel changes later.
选【Rebuild initramfs】
6.5 Would you like to run the nvidia-xconfig utility to automatically update your X configuration file so that the NVIDIA X driver will be used when you restart X? Any pre-existing X configuration file will be backed up.
选【No】
7 验证结果
nvidia-smi