ubuntu18.04 卸载CUDA10.0 安装CUDA10.2、CUDNN

1 卸载CUDA 10.0

进入/usr/local/cuda/bin 目录下,有cuda 自带的卸载工具uninstall_cuda_10.0.pl,输入命令:

cd /usr/local/cuda/bin
sudo ./uninstall_cuda_10.0.pl

卸载完,删除相关文件夹:

sudo rm -rf /usr/local/cuda-10.0/

卸载完毕。

2 安装CUDA 10.2

去官网查看下载
ubuntu18.04 卸载CUDA10.0 安装CUDA10.2、CUDNN_第1张图片按官方命令输入:

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda-repo-ubuntu1804-10-2-local-10.2.89-440.33.01_1.0-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1804-10-2-local-10.2.89-440.33.01_1.0-1_amd64.deb
sudo apt-key add /var/cuda-repo-10-2-local-10.2.89-440.33.01/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda

可能遇到的问题:
报错:无法下载 http://cn.archive.ubuntu.com/ubuntu/pool/universe/f/freeglut/freeglut3_2.8.1-3_amd64.deb 连接失败

已下载 41.5 MB,耗时 41 (1,019 kB/s)                                         
E: 无法下载 http://cn.archive.ubuntu.com/ubuntu/pool/universe/f/freeglut/freeglut3_2.8.1-3_amd64.deb  连接失败 [IP: 91.189.91.38 80]
E: 有几个软件包无法下载,要不运行 apt-get update 或者加上 --fix-missing 的选项再试试?

跳不进去,估计是镜像源的问题,接下来加镜像源:

sudo gedit /etc/apt/sources.list

在开头加上:


deb http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
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

然后重新安装,结果显示如下
ubuntu18.04 卸载CUDA10.0 安装CUDA10.2、CUDNN_第2张图片CUDA10.2 安装成功。

配置CUDA环境
进入主文件夹打开输入命令:

gedit ~/.bashrc

末尾添加环境变量:

export PATH=$PATH:/usr/local/cuda-10.2/bin
export LD_LIBRARY_PATH=/usr/local/cuda-10.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}  

激活环境变量:

source ~/.bashrc

查看是否激活成功:

nvcc -V

ubuntu18.04 卸载CUDA10.0 安装CUDA10.2、CUDNN_第3张图片

3 CUDNN 安装

CUDNN官网
将cuda/include/cudnn.h文件复制到usr/local/cuda/include文件夹:

sudo cp cuda/include/* -R /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/

添加读取权限:

sudo chmod a+r /usr/local/cuda/include/cudnn.h
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*

测试:

cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2

ubuntu18.04 卸载CUDA10.0 安装CUDA10.2、CUDNN_第4张图片ok.

你可能感兴趣的:(ubuntu,linux,运维)