以Ubuntu18.04为例。20.04也类似,centos7不太类似,但是主旨是一样的:按文档来。
文档在这里 https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html
宗旨是:先跟着文档做第2步,随后选择使用.sh文件安装,进入第7步照做
以下所有事请在root下做。
删除历史安装版本
如果可能会有历史安装版本:
sudo apt autoremove cuda
sudo apt --purge remove "*cublas*" "cuda*"
PS:卸载cuda的时候一定要按照官方安装文档提供的方式卸载
安装gcc
用Ubuntu的apt默认安装的gcc是7.5.0,满足cuda11的要求(5及以上),所以直接不指定版本安装也是可以的
apt-get install build-essential
# or: apt-get install gcc
还要做这些事
dpkg --add-architecture i386
apt update
apt install build-essential libc6:i386
禁用nouveau
参考:https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#runfile-nouveau
-
Create a file:
/etc/modprobe.d/blacklist-nouveau.conf
with the following contents:
blacklist nouveau options nouveau modeset=0
-
Regenerate the kernel initramfs:
update-initramfs -u
随后重启,然后lsmod | grep nouveau
,没有东西说明正确
运行脚本安装
安装全部东西,包括显卡驱动。安装成功。
后续工作
修改/etc/profile
添加
export PATH=/usr/local/cuda-11.1/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib64:$LD_LIBRARY_PATH
重启,完成安装
测试
肯定要nvidia-smi
以及,官方测试:
在/usr/local/cuda-11.1/samples
里面sudo make
(需要很久)
然后进入/usr/local/cuda-11.1/samples/bin/x86_64/linux/release
,执行./deviceQuery
和./bandwidthTest
,看结果是否能pass.