cuda版本可能对系统,驱动版本会有影响,修改之前需要先进行确认
1、检查系统版本
source /etc/os-release && echo $VERSION_ID
2、导入apt仓库和其GPG key
# 第一步若输出 16.04
curl -fsSL https://mirrors.aliyun.com/nvidia-cuda/ubuntu1604/x86_64/3bf863cc.pub | apt-key add -
echo "deb https://mirrors.aliyun.com/nvidia-cuda/ubuntu1604/x86_64/ /" > /etc/apt/sources.list.d/cuda.list
# 第一步若输出 18.04
curl -fsSL https://mirrors.aliyun.com/nvidia-cuda/ubuntu1804/x86_64/3bf863cc.pub | apt-key add -
echo "deb https://mirrors.aliyun.com/nvidia-cuda/ubuntu1804/x86_64/ /" > /etc/apt/sources.list.d/cuda.list
3、安装cuda
通过英伟达官方的构建文件可以查到对应的cuda版本的安装命令。
https://gitlab.com/nvidia/container-images/cuda/
以cuda11为例,Dockerfile地址为:
https://gitlab.com/nvidia/container-images/cuda/-/blob/master/dist/11.0.3/ubuntu18.04-x86_64/base/Dockerfile
从镜像中找到对应版本。
# 以升级到cuda11为例
apt-get update && apt-get install -y --no-install-recommends \
cuda-cudart-11-0=11.0.221-1 \
cuda-compat-11-0 &&\
ln -s cuda-11.0 /usr/local/cuda && \
rm -rf /var/lib/apt/lists/*