经过无数次的失败后,终于安装成功,安装过程并不是很难,只是遇到问题时候的解决方式不对,导致花费了不少时间。现将过程整理如下:
电脑的环境:Ubuntu 16.04 64位系统(Windows7双系统)、GPU型号为GeForce GT 540M。
1、先安装相关依赖项
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
2、安装NVIDIA驱动
很多教程都是用驱动文件安装,但我的电脑驱动文件总是安装失败,即使成功了也会遇到很多问题(重启后黑屏、循环登录、NVIDIA X Server Settings仅显示部分信息等)。所以,驱动文件安装方式请自行搜索。
最后,我直接通过系统设置->软件和更新->附件驱动,安装了最新的专有驱动nvidia-375。若总是应用更改失败,则可以尝试更新源,更新方式如下:
sudo vi /etc/apt/sources.list ->替换源 ->sudo apt-get update
替换内容如下(仅供参考):
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
3、CUDA8.0
(1)下载:https://developer.nvidia.com/cuda-downloads
(2)下载完成后执行以下命令:
sudochmod777 cuda_8.0.44_linux.run sudo ./cuda_8.0.44_linux.run 注意:执行后会有一系列提示让你确认,但是注意,有个让你选择是否安装nvidia367驱动时,一定要选择否:Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 367.48?
因为前面我们已经安装了更加新的nvidia367,所以这里不要选择安装。其余的都直接默认或者选择是即可。
(3)环境变量配置
打开~/.bashrc文件: sudo gedit ~/.bashrc
将以下内容写入到~/.bashrc尾部:
export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}} export LD_LIBRARY_PATH=/usr/local/cuda8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
(4)测试CUDA的samples
cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery makesudo ./deviceQuery
如果显示一些关于GPU的信息,则说明安装成功。