Ubuntu 安装nvidia驱动 | 2025

如果执行nvidia-smi报错,可以按照下面的方法重新安装驱动和CUDA
NVIDIA-SMI has failed because it couldn’t communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.

1
2
3
4
5
6
7
8
9
10
11
12
# 清除现有的nvidia和CUDA的残留
sudo apt --purge remove nvidia-*
sudo apt --purge remove cuda-*

# 安装CUDA,[官方工具生成命令](https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=22.04&target_type=deb_local)
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda-toolkit-12-8

# 如果使用docker则安装如下工具包
sudo apt install nvidia-container-toolkit