ubuntu安装cuda

# 更新系统组件,并重启
sudo apt update
sudo apt dist-update
sudo apt upgrade
sudo reboot
# 安装必须的gcc软件
sudo apt-get install manpages-dev
sudo apt-get update
sudo apt install build-essential
# 到nvidia的官网【https://developer.nvidia.com/cuda-downloads】
# 下载系统ubuntu 22.04对应的cuda包,也就是下面的命令
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin
sudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.7.0/local_installers/cuda-repo-ubuntu2204-11-7-local_11.7.0-515.43.04-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2204-11-7-local_11.7.0-515.43.04-1_amd64.deb
sudo cp /var/cuda-repo-ubuntu2204-11-7-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda
# gds相关组件,可以酌情安装,可以参考【https://docs.nvidia.com/gpudirect-storage/release-notes/index.html】
# sudo apt-get install nvidia-gds
# 接下来可以通过Nvidia专有指令,查看系统中的GPU卡。能够成功查看到GPU卡,说明安装成功
nvidia-smi
# 配置相关环境变量
cd /etc/profile.d/
sudo vim /etc/profile.d/cuda.sh
# 将下面的记录,加入到【cuda.sh】文件中
export PATH=/usr/local/cuda-11.7/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.7/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
# 保存cuda.sh文件后,cuda.sh的默认权限即可,重启电脑即可生效全局环境变量
sudo reboot
转载请备注引用地址:编程记忆 » ubuntu安装cuda