linux 安装 cuda
linux
本文字数:705 字 | 阅读时长 ≈ 3 min

linux 安装 cuda

linux
本文字数:705 字 | 阅读时长 ≈ 3 min

1. cuda 下载

在此处选择自己想要下载的 cuda 版本cuda-toolkit-archive

以 cuda 11.8 版本为例,按如图进行选择,我这里是 centos 系统,其它系统如实选择即可,这里选择 runfile 下载

在页面下面有直接的安装命令,这里我的命令是

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 安装

  1. 执行第一条命令
(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]
  1. 执行第二条命令
    我这边已经安装 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

详细说明:

  1. 添加环境变量
    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 即可

4月 06, 2025
3月 10, 2025
12月 31, 2024