Ubuntu18.04 + CUDA10.0 + CUDNN7 一键配置脚本
程序员文章站
2022-05-27 14:42:24
...
最近实验过程中,难免有时候电脑故障,多次故障导致重装系统时非常不方便,因此写脚本完成系统安装后的驱动安装和相关的程序安装过程。
软件配置如下:
nvidia-driver-410
cuda-10.0
cudnn-7
docker-ce
nvidia-docker2
atom
typora
# 以及一些其他相关的软件
安装脚本如下,完成 Ubuntu18.04 系统安装之后将下面的脚本拷贝写入文件中,例如 ubuntu.sh
, 打开终端并进入存放脚本的文件夹,执行命令sudo su
使用 root 用户进行操作, 在 root 用户模式下, sh ubuntu.sh
执行脚本,即可完成基本实验环境配置。执行过程需要保持联网!
#! /sbin/bash
# From Luo Xin
# Email: [email protected]
sudo tee /etc/apt/sources.list <<EOF
deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
EOF
sudo add-apt-repository ppa:graphics-drivers/ppa
wget -qO - https://typora.io/linux/public-key.asc | sudo apt-key add -
sudo add-apt-repository 'deb https://typora.io/linux ./'
sudo apt-get update
sudo apt-get install typora
sudo ubuntu-drivers autoinstall
sudo apt install vim exfat-fuse exfat-utils unrar p7zip-full p7zip-rar rar unzip gnome-tweak-tool gnome-shell-extensions chrome-gnome-shell gtk2-engines-pixbuf libxml2-utils build-essential gcc-4.8 gcc-4.8-multilib g++-4.8 g++-4.8-multilib gcc-5 gcc-5-multilib g++-5 g++-5-multilib gcc-6 gcc-6-multilib g++-6 g++-6-multilib gcc-7 gcc-7-multilib g++-7 g++-7-multilib curl terminator -y
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 40
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 50
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 40
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 50
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 60
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 70
sudo apt-get install -y --no-install-recommends gnupg2 curl ca-certificates
curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub | apt-key add -
echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda.list
echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list
CUDA_VERSION=10.0.130
CUDA_PKG_VERSION=10-0=$CUDA_VERSION-1
NCCL_VERSION=2.3.5
CUDNN_VERSION=7.3.1.20
apt-get update
apt-get install -y --no-install-recommends cuda-cudart-$CUDA_PKG_VERSION cuda-compat-10-0=410.48-1
apt-get install -y --no-install-recommends cuda-libraries-$CUDA_PKG_VERSION cuda-nvtx-$CUDA_PKG_VERSION libnccl2=$NCCL_VERSION-2+cuda10.0
apt-mark hold libnccl2
apt-get install -y --no-install-recommends libcudnn7=$CUDNN_VERSION-1+cuda10.0
apt-mark hold libcudnn7
apt-get install -y --no-install-recommends cuda-libraries-dev-$CUDA_PKG_VERSION cuda-nvml-dev-$CUDA_PKG_VERSION cuda-minimal-build-$CUDA_PKG_VERSION cuda-command-line-tools-$CUDA_PKG_VERSION libnccl-dev=$NCCL_VERSION-2+cuda10.0
apt-get install -y --no-install-recommends libcudnn7=$CUDNN_VERSION-1+cuda10.0 libcudnn7-dev=$CUDNN_VERSION-1+cuda10.0
apt-mark hold libcudnn7
apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
apt-get update
apt-get install -y docker-ce
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update
apt-get install -y nvidia-docker2 nvidia-container-runtime
sudo pkill -SIGHUP dockerd
sudo groupadd docker
sudo gpasswd -a ${USER} docker
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<EOF
{
"runtimes": {
"nvidia": {
"path": "/usr/bin/nvidia-container-runtime",
"runtimeArgs": []
}
}
}
EOF
sudo pkill -SIGHUP dockerd
sudo add-apt-repository ppa:webupd8team/atom
sudo apt update
sudo apt install atom -y
sudo apt install typora -y