> ## Content Index
> Fetch the complete content index at: https://sgpublic.xyz/llms.txt
> Use this file to discover other available public pages before exploring further.

# Debian 12 Cuda 环境安装
- URL: https://sgpublic.xyz/p/2025/01/6aac9cb1810a480001533605/
- Published: 2025-01-21T15:27:53.000Z
- Updated: 2025-01-21T15:27:53.000Z
- Author: Haven Madray
- Tags: AI 与算力, NVIDIA/CUDA, #wp-post

> 参考文档：[https://forums.developer.nvidia.com/t/notice-cuda-linux-repository-key-rotation/212772](https://forums.developer.nvidia.com/t/notice-cuda-linux-repository-key-rotation/212772?ref=sgpublic.xyz)

NVIDIA 更新了密钥，官方文档的旧版本存档中所写的方法不再适用，新方法如下：

如果要运行神经网络项目，则还需要安装 cudnn。

```shell
sudo apt-get install cudnn9-cuda-11
```

此处不能安装 `cudnn9-cuda-11-4`，因为其限定特定的 cudnn 版本，由于 cuda 不限定 cudnn 的次要版本，根据主要版本选择即可。

更新缓存并安装：

```shell
sudo apt-get update
sudo apt-get install cuda-toolkit-11-4
```

查看驱动支持的 cuda 版本：

```shell
madray@nas:~$ nvidia-smi 
Tue Jan 21 23:05:40 2025       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.256.02   Driver Version: 470.256.02   CUDA Version: 11.4     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  Off  | 00000000:03:00.0 N/A |                  N/A |
| N/A   28C    P0    N/A /  N/A |      0MiB /  1997MiB |     N/A      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+
```

可以看到这里输出的是 `CUDA Version: 11.4`，所以安装 `cuda-toolkit-11-4`。

（可选）修改仓库源为官方国内镜像：

```shell
sudo sed -i 's/developer.download.nvidia.com/developer.download.nvidia.cn/' /etc/apt/sources.list.d/cuda-debian10-$(arch).list
```

根据系统版本下载 `cuda-keyring` 并安装：

```shel
wget https://developer.download.nvidia.cn/compute/cuda/repos/debian10/x86_64/cuda-keyring_1.1-1_all.deb
sudo apt-get install ./cuda-keyring_1.1-1_all.deb
```

若使用 apt 安装，NVIDIA 对于不同版本的 Debian 仓库源支持的 CUDA 版本不同，此处安装 11.4 需 Debian Buster 才能使用 apt 安装。

也可以使用我做好的开源项目直接构建 Docker：[sgpublic/poetry-docker](https://github.com/sgpublic/poetry-docker?ref=sgpublic.xyz)（由于构建数量过多，因此推荐自行把源码拉下来利用 gradlew 构建）。