1. cuda 下载
在此处选择自己想要下载的 cuda 版本cuda-toolkit-archive
以 cuda 11.8 版本为例,按如图进行选择,我这里是 centos 系统,其它系统如实选择即可,这里选择 runfile 下载
- network:网络安装包,安装包较小,需要在主机内联网下载实际的安装包
- local:本地安装包。安装包较大,包含每一个下载安装组件的安装包

在页面下面有直接的安装命令,这里我的命令是
wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
sudo sh cuda_11.8.0_520.61.05_linux.run
2. cuda 安装
- 执行第一条命令
(python) ➜ ~ wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
--2024-07-14 17:39:11-- https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
Resolving developer.download.nvidia.com (developer.download.nvidia.com)... 152.199.39.144
Connecting to developer.download.nvidia.com (developer.download.nvidia.com)|152.199.39.144|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4336730777 (4.0G) [application/octet-stream]
Saving to: ‘cuda_11.8.0_520.61.05_linux.run’
cuda_11.8.0_520.61.05_linux.run 100%[===============================================================================================>] 4.04G 149MB/s in 39s
2024-07-14 17:39:50 (107 MB/s) - ‘cuda_11.8.0_520.61.05_linux.run’ saved [4336730777/4336730777]
- 执行第二条命令
我这边已经安装 cuda driver 了,所以我安装 cuda 就可以,其他的均不安装,按照如下选择

(python) ➜ ~ sudo sh cuda_11.8.0_520.61.05_linux.run
===========
= Summary =
===========
Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-11.8/
Please make sure that
- PATH includes /usr/local/cuda-11.8/bin
- LD_LIBRARY_PATH includes /usr/local/cuda-11.8/lib64, or, add /usr/local/cuda-11.8/lib64 to /etc/ld.so.conf and run ldconfig as root
To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-11.8/bin
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 520.00 is required for CUDA 11.8 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
sudo <CudaInstaller>.run --silent --driver
Logfile is /var/log/cuda-installer.log
也可以使用 --prefix
选项指定 CUDA Toolkit 的安装路径。例如,如果你想安装到 /opt/cuda-11.8
,你可以运行:
sudo sh cuda_11.8.0_520.61.05_linux.run --silent --toolkit --toolkitpath=/opt/cuda-11.8
详细说明:
--silent
:静默安装,不会出现交互式界面。--toolkit
:仅安装 CUDA Toolkit(不会安装驱动)。--toolkitpath=/opt/cuda-11.8
:将 CUDA Toolkit 安装到/opt/cuda-11.8
。
- 添加环境变量
vim ~/.zshrc
,如果是 bash 的话vim ~/.zshrc
修改为vim ~/.bashrc
,然后添加下面语句,保存后执行source ~/.zshrc
即可修改成功
添加下面语句
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.8/lib64
export PATH=$PATH:/usr/local/cuda-11.8/bin
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda-11.8
你的 CUDA 将会安装到指定路径 /usr/local/cuda-11.8
,并且可以全局使用。🚀
3. 多 cuda 版本共存
只需要安装多个 cuda,然后修改环境变量为 xxx/cuda-xx.x
即可
本文由 Yonghui Wang 创作,采用
知识共享署名4.0
国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为:
Mar 13, 2025 11:30 pm