首先禁用ubuntu系统自带的nouveau驱动
sudo gedit /etc/modprobe.d/blacklist.conf
在文本最后添加如下:
blacklist rivafb
blacklist vga16fb
blacklist nouveau
blacklist nvidiafb
blacklist rivatv
保存,然后执行下面命令更新内核
sudo update-initramfs -u
接下来,输入reboot重启,重启后,执行下面的命令,如果没有屏幕输出,说明禁用nouveau成功
lsmod | grep nouveau
nvidia官网下载适配显卡的驱动。我的主机显卡为3080,对应的驱动名称为
NVIDIA-Linux-x86_64-455.45.01.run
卸载之前安装的驱动使用如下命令
sudo apt-get --purge remove nvidia*
sudo apt autoremove
为方便及加速安装依赖和库更换国内源
1.备份原始源文件sources.list
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
2.修改源文件sources.list,添加权限及编辑文本添加国内源
sudo chmod 777 /etc/apt/sources.list
sudo gedit /etc/apt/sources.list
删除原有源,可以选择国内源复制到sources.list文件中
阿里源
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
自己电脑配置的源
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security multiverse
保存sources.list文件,更新源
sudo apt update
sudo apt-get install gcc g++ make
进入到包含驱动的文件夹,修改权限后安装驱动
sudo chmod +x NVIDIA-Linux-x86_64-455.45.01.run
sudo ./NVIDIA-Linux-x86_64-455.45.01.run
按照出来的提示按照,其中
1.即使预安装脚本执行失败也继续安装? 选择继续安装
2.提示安装32位的兼容库? 回车
3.自动更新X配置文件? 选NO
直至安装完成,ok
安装完成后重新启动系统
reboot
重启主机后,验证显卡是否安装成功
nvidia-smi
首先在Nvidia官网下载适合自己显卡的cuda版本,本次使用 runfile的方式安装。
卸载原来的cuda,10.0可以修改成原来自己安装的版本
sudo /usr/local/cuda-10.0/bin/uninstall_cuda_10.0.pl
卸载之后,会发现 /usr/local/cuda-10.0目录下仍然还有文件存在,这是cudnn文件,所以还需要将cuda-10.0文件删除干净
sudo rm -rf /usr/local/cuda-10.0
我下载好的cuda版本为
cuda_11.1.0_455.23.05_linux.run
进入到包含驱动的文件夹,修改权限后安装驱动
sudo chmod +x cuda_11.1.0_455.23.05_linux.run
sudo ./cuda_11.1.0_455.23.05_linux.run
按照出来的提示按照,其中
1.是否接受EULA? 输入accept
2.cuda安装? 选择不安装驱动,其他默认安装install
直至安装完成
还需要配置环境变量
sudo gedit ~/.bashrc
添加
export PATH=/usr/local/cuda-11.1/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
或者是添加
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.1/lib64
export PATH=$PATH:/usr/local/cuda-11.1/bin
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda-11.1
保存,然后刷新环境变量,输入
source ~/.bashrc
检查当前的cuda版本
nvcc -V
首先在Nvidia官网下载适合自己显卡的cudnn版本,本次使用 runfile的方式安装。
这里我们会使用到的有
cuDNN Library for Linux (x86_64) (tgz)
cuDNN Runtime Library for Ubuntu20.04 x86_64
cuDNN Developer Library for Ubuntu20.04 x86_64 (Deb)
cuDNN Code Samples and User Guide for Ubuntu20.04 x86_64 (Deb)
sudo rm -rf /usr/local/cuda/include/cudnn.h
sudo rm -rf /usr/local/cuda/lib64/libcudnn
卸载之后,会发现 /usr/local/cuda-10.0目录下仍然还有文件存在,这是cudnn文件,所以还需要将cuda-10.0文件删除干净
sudo rm -rf /usr/local/cuda-10.0
将下载的 cuDNN Library for Linux (x86_64) 解压,并在解压出cuda的文件夹中打开终端,将解压出来的文件复制到安装好的CUDA中,命令如下:
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
更改权限
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
接下来安装Deb包,命令如下:
sudo dpkg -i libcudnn8_8.0.5.39-1+cuda11.1_amd64.deb
sudo dpkg -i libcudnn8-dev_8.0.5.39-1+cuda11.1_amd64.deb
sudo dpkg -i libcudnn8-samples_8.0.5.39-1+cuda11.1_amd64.deb
安装结束后重启,测试是否安装成功,
方法1:
cp -r /usr/src/cudnn_samples_v8/ ~
cd ~/cudnn_samples_v8/mnistCUDNN/
make clean && make
./mnistCUDNN
Test passed!则成功
方法2:
cd /usr/local/cuda/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery
Result = PASS则成功
1.https://blog.csdn.net/qq_33200967/article/details/80689543#_10.
2.https://www.cnblogs.com/booturbo/p/13960935.html.
3.https://www.cnblogs.com/luofeel/p/8654964.html.
4.https://blog.csdn.net/hjxu2016/article/details/97023248#cuDNN_13.
5.https://www.jb51.net/article/192493.htm.
6.https://blog.doiduoyi.com/authors/1584446358138.
7.cuda如何做软连接切换
8.ubuntu18.04安装nvidia驱动,3种方式图文详解+卸载教程