1. cuda 的下載下傳與安裝方法選擇
到 CUDA Toolkit Download 下載下傳所需版本,以
cuda_9.0.176_384.81_linux.run
為例:

建議選擇使用
.run
檔案安裝,因為使用
.deb
可能會将已經安裝的較新的顯示卡驅動替換。
2. cuda 安裝
進入到放置
cuda_9.0.176_384.81_linux.run
的目錄:
sudo chmod +x cuda_9._384._linux.run # 為 cuda_9._384._linux.run 添加可執行權限
./cuda_9._384._linux.run # 安裝 cuda_9._384._linux.run
在安裝過程中截取其中比較重要的幾個選擇:
Do you accept the previously read EULA?
accept/decline/quit: accept
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 ?
(y)es/(n)o/(q)uit: n # 如果在這之前已經安裝好更高版本的顯示卡驅動就不需要再重複安裝,如果需要重複安裝就選擇 yes,此外還需要關閉圖形界面。
Install the CUDA Toolkit?
(y)es/(n)o/(q)uit: y
Enter Toolkit Location
[ default is /usr/local/cuda- ]: # 一般選擇預設即可,也可以選擇安裝在其他目錄,在需要用的時候指向該目錄或者使用軟連接配接 link 到 /usr/local/cuda。
/usr/local/cuda- is not writable.
Do you wish to run the installation with 'sudo'?
(y)es/(n)o: y
Please enter your password:
Do you want to install a symbolic link at /usr/local/cuda? # 是否将安裝目錄通過軟連接配接的方式 link 到 /usr/local/cuda,yes or no 都可以,取決于你是否使用 /usr/local/cuda 為預設的 cuda 目錄。
(y)es/(n)o/(q)uit: n
Install the CUDA Samples?
(y)es/(n)o/(q)uit: n
前面選擇的一些彙總:
Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-9.0
Samples: Not Selected
Please make sure that
- PATH includes /usr/local/cuda-/bin
- LD_LIBRARY_PATH includes /usr/local/cuda-/lib64, or, add /usr/local/cuda-/lib64 to /etc/ld.so.conf and run ldconfig as root
To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-/bin
Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-/doc/pdf for detailed information on setting up CUDA.
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least is required for CUDA 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
安裝完成後可以在
/usr/local
目錄下看到:
cuda- # 筆者之前安裝的cuda-8.0
cuda- # 剛剛安裝的cuda-9.0
cuda # cuda-8.0 的軟連接配接
3. 多個 cuda 版本之間進行切換
将~/.bashrc 或 ~/.zshrc 下與cuda相關的路徑都改為 /usr/local/cuda/ 而不使用 /usr/local/cuda-8.0/ 或/usr/local/cuda-9.0/。
#在切換cuda版本時
rm -rf /usr/local/cuda#删除之前建立的軟連結
sudo ln -s /usr/local/cuda-/ /usr/local/cuda/
nvcc --version #檢視目前 cuda 版本
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) - NVIDIA Corporation
Built on Mon_Jan_23_12:24:11_CST_2017
Cuda compilation tools, release , V8
#cuda8.0 切換到 cuda9.0
rm -rf /usr/local/cuda
sudo ln -s /usr/local/cuda-/ /usr/local/cuda/
nvcc --version