2 - Ubuntu 16.04 + nvidia + cuda9.1

很久没用实验室的电脑,觉得很浪费,所以想好好重整一下环境。本来电脑上是只有一个ubuntu系统,现在装双系统,win10和ubuntu,全部从头安装,都装在固态硬盘上。安装系统的过程就不说了,ubuntu的安装见系列1。

这是一个系列:
1、Ubuntu 系统安装
2、Ubuntu 16.04 + nvidia + cuda9.1
3、Ubuntu 基本工作环境 + 深度学习环境配置
4、Ubuntu 16.04 + SSR

一、安装nvidia驱动

1、首先去官网上适合你的GPU驱动:

2 - Ubuntu 16.04 + nvidia + cuda9.1_第1张图片
my_type_1
2 - Ubuntu 16.04 + nvidia + cuda9.1_第2张图片
my_type_2

2、执行如下语句,安装:

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt-get install nvidia-390   # 这边数字对应上面搜索出的版本
sudo apt-get install mesa-common-dev
sudo apt-get install freeglut3-dev

3、执行完上述后,重启: sudo reboot
4、输入nvidia-smi,如果出现了你的GPU列表,则说明驱动安装成功了。另外也可以通过nvidia-settings查看自己机器上详细的GPU信息。

如果驱动安装有问题,见我这篇:ubuntu 16.04 nvidia显卡驱动相关问题。

二、安装cuda

cuda是nvidia的编程语言平台,想使用GPU就必须要使用cuda。
1、从这里cuda9.1找适合自己的安装文件。

2 - Ubuntu 16.04 + nvidia + cuda9.1_第3张图片
download_cuda

下载下面第一个cuda9.1的runfile(local)文件:cuda_9.1.85_387.26_linux.run
这里是nvidia给出的官方安装指南,遇到问题时可以查阅 。

2、进入下载好的runfile文件所在目录下,执行如下语句,运行runfile文件:

sudo sh cuda_9.1.85_387.26_linux.run 

注意:因为驱动之前已经安装,这里就不要选择安装驱动(第一条跳出问 cuda accelerated graphic driver之类的问你要不要安装,选no就行)。其余的都直接continue或者选yes即可。如果报错:

Do you accept the previously read EULA?
accept/decline/quit: accept

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 387.26?
(y)es/(n)o/(q)uit: no

Install the CUDA 9.1 Toolkit?
(y)es/(n)o/(q)uit: y

Enter Toolkit Location
 [ default is /usr/local/cuda-9.1 ]:                         

Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y

Install the CUDA 9.1 Samples?
(y)es/(n)o/(q)uit: y

Enter CUDA Samples Location
 [ default is /home/mdt ]: 

Installing the CUDA Toolkit in /usr/local/cuda-9.1 ...
Missing recommended library: libXi.so
Missing recommended library: libXmu.so

Installing the CUDA Samples in /home/mdt ...
Copying samples to /home/mdt/NVIDIA_CUDA-9.1_Samples now...
Finished copying samples.

===========
= Summary =
===========

Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-9.1
Samples:  Installed in /home/mdt, but missing recommended libraries

Please make sure that
 -   PATH includes /usr/local/cuda-9.1/bin
 -   LD_LIBRARY_PATH includes /usr/local/cuda-9.1/lib64, or, add /usr/local/cuda-9.1/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-9.1/bin

Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-9.1/doc/pdf for detailed information on setting up CUDA.

***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 384.00 is required for CUDA 9.1 functionality to work.
To install the driver using this installer, run the following command, replacing  with the name of this run file:
    sudo .run -silent -driver

Logfile is /tmp/cuda_install_2139.log

Solution:

sudo apt-get install libglu1-mesa libxi-dev libxmu-dev libglu1-mesa-dev

3、打开“profile”文件: sudo gedit /etc/profile
在末尾处添加(注意不要有空格,不然会报错):

# 可以先去check一下自己的/usr/local/下有没有或者是不是cuda-9.1
export PATH=/usr/local/cuda-9.1/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-9.1/lib64$LD_LIBRARY_PATH

4、重启电脑: sudo reboot
5、测试cuda的samples:

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

如果显示的是一些关于GPU的信息,则说明安装成功了。

参考目录:
https://blog.csdn.net/u010837794/article/details/63251725

========================================================

查看cuda安装版本:

nvcc -V

你可能感兴趣的:(2 - Ubuntu 16.04 + nvidia + cuda9.1)