Ubuntu16.04 安装NVIDIA驱动 和 CUDA

安装NVIDIA驱动

避免sudo apt-get install nvidia-*安装方式造成登录界面循环。

1. ubuntu 16.04默认安装了第三方开源的驱动程序nouveau,安装nvidia显卡驱动首先需要禁用nouveau,不然会碰到冲突的问题,导致无法安装nvidia显卡驱动。

编辑文件blacklist.conf

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

若未安装vim则sudo apt-get install vim安装或使用vi

在文件最后部分插入以下两行内容

blacklist nouveau

options nouveau modeset=0

更新系统

sudo update-initramfs -u

重启系统(一定要重启)

 

验证nouveau是否已禁用

lsmod | grep nouveau

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

 

2. 在英伟达的官网上查找你自己电脑的显卡型号然后下载相应的驱动。网址:http://www.nvidia.cn/page/home.html

我下载的版本:NVIDIA-Linux-x86_64-440.82.run(注意不同的版本最后安装执行的具体选项不同)

下载后的run文件拷贝至home目录下。

 

3. 在ubuntu下按ctrl+alt+f1进入命令行界面,

然后在命令行界面下输入:

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

然后卸载掉原有驱动:

     sudo apt-get remove nvidia-*  (若安装过其他版本或其他方式安装过驱动执行此项)

 

4. 

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

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

安装:

     sudo ./NVIDIA-Linux-x86_64-396.18.run -no-x-check -no-nouveau-check -no-opengl-files //只有禁用opengl这样安装才不会出现循环登陆的问题

-no-x-check:安装驱动时关闭X服务

-no-nouveau-check:安装驱动时禁用nouveau

-no-opengl-files:只安装驱动文件,不安装OpenGL文件

 

安装过程中的选项:

1. There appears to already be a driver installed on your system (version:      
  390.42).  As part of installing this driver (version: 390.42), the existing  
  driver will be uninstalled.  Are you sure you want to continue? 
  Continue installation      Abort installation 
(选择 Coninue,如果是重装的话)
2. The distribution-provided pre-install script failed!  Are you sure you want
  to continue?                                                                 
 Continue installation      Abort installation       
(选择 Cotinue)
3. Would you like to register the kernel module sources with DKMS? This will    
  allow DKMS to automatically build a new module, if you install a different   
  kernel later.
Yes                       No  
(这里选 No)
4. Install NVIDIA's 32-bit compatibility libraries?
    Yes                       No  
(这里选 No)
5. Installation of the kernel module for the NVIDIA Accelerated Graphics Driver
  for Linux-x86_64 (version 390.42) is now complete.                           
  OK
6.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                       No  
(这里选 Yes)

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

 

5. 

挂载Nvidia驱动:

modprobe nvidia

检查驱动是否安装成功:

nvidia-smi

如果出现如下提示,则说明安装成功:

sudo reboot 重启

 

6. 安装过程中出现的错误及解决

错误1.

ERROR: Unable to load the kernel module 'nvidia.ko'.  This happens most
   frequently when this kernel module was built against the wrong or
   improperly configured kernel sources, with a version of gcc that differs
   from the one used to build the target kernel, or if a driver such as
   rivafb/nvidiafb is present and prevents the NVIDIA kernel module from
   obtaining ownership of the NVIDIA graphics device(s), or NVIDIA GPU
   installed in this system is not supported by this NVIDIA Linux graphics
   driver release.


遇到此问题,可以安装后面正文的方法,重新尝试安装,
还有一个类似于此的错误,也是ERROR后面一大堆,但是kernel module后面是“nvidia-drm”,此问题是由于之前安装过驱动的残留所致,请参考第3步后重新安装。
错误2. 在安装的最后一步,没有提示安装成功,而是显示

Error:Unable to load the 'nvidia-drm' kernel module .


出现这个问题最有可能的原因是你安装的Ubuntu是UEFI模式启动的,但是在BIOS中却打开了Security BOOT选项。 正确做法是禁用该选项,具体方式请百度(我就是这一步折腾的我,其实一直没有找到具体原因)

 

安装 CUDA

进入下载的文件路径

sudo sh cuda_9.0.176_384.81_linux.run

出现说明之后,按Ctrl + C键跳过,接受之后会问你是否需要安装驱动,选择无,其余选择是直至安装完成。

 

配置环境变量,运行如下命令打开个人资料文件

sudo gedit  /etc/profile

打开文件后在文件末尾添加路径,也就是安装目录,命令如下: 

export  PATH=/usr/local/cuda-9.0/bin:$PATH
export  LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64$LD_LIBRARY_PATH 
 

 保存,然后重启电脑,进入终端

 

cd  /usr/local/cuda-9.0/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery


如果result = PASS,则安装成功,否则失败,可能原因是环境未配置好,或者是cuda与驱动版本不兼容。

 

  • 5
    点赞
  • 48
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值