Ubuntu 16.04 安装Nvidia驱动

注意:1、首先确保电脑Secure boot已禁用,否则安装Nvidia会失败或者不可用。

           2、在Nvidia官网下载相应版本的驱动

1、删除原有驱动

sudo apt-get remove --purge nvidia*

2、禁用nouveau驱动

sudo gedit /etc/modprobe.d/blacklist.conf 

 在文档结尾添加以下内容:

blacklist nouveau

blacklist lbm-nouveau

options nouveau modeset=0

alias nouveau off

alias lbm-nouveau off 

 保存文件并关闭nouveau:

echo options nouveau modeset=0 | sudo tee -a /etc/modprobe.d/nouveau-kms.conf

然后重启电脑:

update-initramfs -u

reboot

3、验证 nouveau是否已禁用

lsmod | grep nouveau

 没有信息显示,说明nouveau已被禁用,接下来可以安装nvidia的显卡驱动。

4、获取Kernel source

sudo apt-get install linux-source

sudo apt-get install linux-headers-x.x.x-x-generic

其中x.x.x-x可以通过uname -r查看相应版本号(系统内核版本),如下图:Ubuntu 16.04 安装Nvidia驱动

5、安装NVIDIA驱动

1)同时按下ctrl+alt+f1进入命令行界面

关闭图像界面:

sudo service lightdm stop //这个是关闭图形界面,不执行会出错。

2)给.run驱动文件赋予执行权限: 

sudo chmod a+x NVIDIA-Linux-x86_64-430.64.run

3)开始安装 

sudo ./NVIDIA-Linux-x86_64-430.09.run -no-x-check -no-nouveau-check -no-opengl-files 

说明: -no-x-check:安装驱动时关闭X服务
            -no-nouveau-check:安装驱动时禁用nouveau
            -no-opengl-files:只安装驱动文件,不安装OpenGL文件(避免循环登录)

4)安装过程中的选项:

The distribution-provided pre-install script failed! Are you sure you want to continue? 选择 yes 继续。
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 继续。
问题没记住,选项是:install without signing
问题大概是:Nvidia’s 32-bit compatibility libraries? 选择 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 继续

这些选项如果选择错误可能会导致安装失败,没关系,只要前面不出错,多尝试几次就好。

5)重启电脑会自动进入图像界面

6)检查是否安装成功

nvidia-smi

出现如下界面代表安装成功:

Ubuntu 16.04 安装Nvidia驱动

如果出现以下错误信息:

NVIDIA-SMI has failed because it couldn‘t communicate with NVIDIA driver. Make sure that the latest driver is installed and running.

解决方案

sudo apt-get install dkms

7)如果以上步骤安装成功但无法外接显示器进行投屏

解决方案: 

sudo apt install nvidia-settings 

sudo service  lightdm restart