方法
- 用deb方式安装的cuda,进行卸载。我目前是卸载10.1,安装10.2
# 卸载cuda
sudo apt-get --purge remove <package_name>
注:package_name即为cuda
# 自动删除一些没有依赖的cuda文件(此处注意不要删掉ros相关,以及内核文件相关,要么就不执行这一句,避免误删)
sudo apt autoremove
# 删除cuda-10.1文件夹
sudo rm -rf /usr/local/cuda
# 查看关联文件,逐个删除
sudo find / -name cuda-*
# 尤其注意如下几个文件位置
sudo rm -rf /var/cuda*
sudo rm -rf /usr/share/doc/cuda*
sudo rm /etc/apt/sources.list.d/cuda*
sudo rm /usr/lib/pkgconfig/cuda*
# 自动删除
sudo apt-get autoclean
# 删除cuDNN
cd /usr/local/include/
sudo rm cudnn.h
cd /usr/local/lib/
sudo rm libcudnn.*
# 配置文件
sudo rm /etc/ld.so.conf.d/cuda-10-1.conf
# 旧的更新地址
sudo rm /etc/apt/sources.list.d/cuda-10-1-local-10.1.243-418.87.00.list.save
# 旧的dpkg信息
sudo rm /var/lib/dpkg/info/cuda-*
- 下载cuda-10.2
# 网址
[cuda-10.2 official link]](https://developer.nvidia.com/cuda-10.2-download-archive?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1804&target_type=deblocal)
# 按照官网指令执行
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
# 安装补丁
sudo dpkg -i cuda-repo-ubuntu1804-10-2-local_10.2.1-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1804-10-2-local_10.2.2-1_amd64.deb
- 下载cudnn-7.6.5
# 网址
https://developer.nvidia.com/rdp/cudnn-archive
# 找到这三个文件
# 包含了某些深度学习应用
# cuDNN Runtime Library for Ubuntu18.04 (Deb)
sudo dpkg -i libcudnn7_7.6.5.32-1+cuda10.2_amd64.deb
# 包含了在Ubuntu系统上开发深度学习时所需的cuDNN头文件
# cuDNN Developer Library for Ubuntu18.04 (Deb)
sudo dpkg -i libcudnn7-dev_7.6.5.32-1+cuda10.2_amd64.deb
# 包含了cuDNN例程和相关文档
# cuDNN Code Samples and User Guide for Ubuntu18.04 (Deb)
sudo dpkg -i libcudnn7-doc_7.6.5.32-1+cuda10.2_amd64.deb
- 配置环境变量
# 配置环境变量
sudo gedit ~/.zshrc
export PATH=/usr/local/cuda-10.2/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
# 更新环境变量
source ~/.zshrc
# 查看cuda是否安装成功
nvcc -V
# 我的显示如下
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:24:38_PDT_2019
Cuda compilation tools, release 10.2, V10.2.89
- 重启电脑,查看是否正常
# 输入命令
$ nvidia-smi
# 显示
Wed Jan 4 11:06:49 2023
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.33.01 Driver Version: 440.33.01 CUDA Version: 10.2 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce RTX 207... On | 00000000:01:00.0 On | N/A |
| 40% 24C P8 24W / 215W | 532MiB / 7979MiB | 1% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 1102 G /usr/lib/xorg/Xorg 56MiB |
| 0 1159 G /usr/bin/gnome-shell 49MiB |
| 0 2326 G /usr/lib/xorg/Xorg 259MiB |
| 0 2481 G /usr/bin/gnome-shell 156MiB |
| 0 2525 G /opt/teamviewer/tv_bin/TeamViewer 2MiB |
| 0 2938 G gnome-control-center 2MiB |
+-----------------------------------------------------------------------------+