最近经常更新老机器上的显卡驱动, 记录一下.

  • 更新显卡驱动
  • 更新CUDA
  • 更新 Cudnn

更新显卡驱动

先去官网下载最新的显卡驱动, 放到服务器上, 然后执行

sudo chmod u+x ./NNVIDIA-Linux-x86_64-535.86.05.run
sudo ./NVIDIA-Linux-x86_64-535.86.05.run

然后一路安装即可, 可能会遇到 X Server 没关闭的错误, 那就执行下面的命令即可.(我是Ubuntu)

sudo service lightdm stop
# or
sudo systemctl stop gdm

然后重新执行即可.

如果遇到提示

ERROR: The Nouveau kernel driver is currently in use by your system. 

那么执行下面命令

sudo vim /etc/default/grub
# 然后修改成下面这样
# GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nouveau.modeset=0"
# 修改完后保存退出, 更新
sudo update-grub
# 重启
sudo reboot
ERROR: Unable to find the development tool `cc` in your path; please make sure that you have the package 'gcc' installed.  If gcc is installed on your system, then please check that `cc` is in your PATH.

应该是没安装 gcc

sudo apt install gcc
ERROR: Unable to find the development tool `make` in your path; please make sure that you have the package 'make' installed.  If make is installed on your system, then please check that `make` is in your PATH.

应该是没安装 make

sudo apt install make

然后重新执行即可.

更新 CUDA

先选择cuda, 官网, 我这里依次选择 Linux -> x86_64 -> Ubuntu -> 22.04 -> runfile(local)

然后会显示两条命令

wget https://developer.download.nvidia.com/compute/cuda/12.2.0/local_installers/cuda_12.2.0_535.54.03_linux.run
sudo sh cuda_12.2.0_535.54.03_linux.run

运行

wget https://developer.download.nvidia.com/compute/cuda/12.2.0/local_installers/cuda_12.2.0_535.54.03_linux.run
# 这里大概要下好几分钟
# 修改权限
sudo chmod  u+x ./cuda_12.2.0_535.54.03_linux.run
# 执行
sudo ./cuda_12.2.0_535.54.03_linux.run
# 依次选择
# continue -> 输入 accept -> 在 Driver 处回车(让他没有打上X) -> install -> update(yes)

# 验证一下装没装上
nvcc -V 
# nvcc: NVIDIA (R) Cuda compiler driver
# Copyright (c) 2005-2023 NVIDIA Corporation
# Built on Tue_Jun_13_19:16:58_PDT_2023
# Cuda compilation tools, release 12.2, V12.2.91
# Build cuda_12.2.r12.2/compiler.32965470_0
# 一般这个时候 /usr/local/cuda 都是链接到了 cuda-12.2 上了(要注意是不是.)
# 不知道为什么后面又要手动链接

# 有时候需要在.bashrc中添加环境变量
export CUDA_HOME=/usr/local/cuda:$CUDA_HOME
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
export LIBRARY_PATH=/usr/local/cuda/lib64:$LIBRARY_PATH

更新 Cudnn

官网 下载对应cuda版本的cudnn, 需要登录, 我下载的是 tar.zx 的, 然后上传到服务器上, 然后执行

# 解压
tar -xvf cudnn-linux-x86_64-8.9.2.26_cuda12-archive.tar.xz
# 复制到cuda目录下
sudo cp ./cudnn-linux-x86_64-8.9.2.26_cuda12-archive/include/cudnn*.h /usr/local/cuda/include
sudo cp  ./cudnn-linux-x86_64-8.9.2.26_cuda12-archive/lib/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*

然后就完成啦!