Setting Up Ubuntu in GPU Server
By: Eason Sung
Tags: Ubuntu 20 04, Ubuntu, Cuda, Nvidia Docker, Cudnn

Environment

OS: Ubuntu 20.04

GPU: GeForce RTX 3090

Install Nvidia Driver

$ sudo add-apt-repository ppa:graphics-drivers/ppa

$ sudo apt update

$ sudo apt install ubuntu-drivers-common



$ ubuntu-drivers devices

== /sys/devices/pci0000:00/0000:00:03.2/0000:0d:00.0 ==

modalias : pci:v000010DEd00002204sv00001462sd00003881bc03sc00i00

vendor : NVIDIA Corporation

driver : nvidia-driver-460 - distro non-free recommended

driver : nvidia-driver-460-server - distro non-free

driver : xserver-xorg-video-nouveau - distro free builtin



$ sudo apt install nvidia-driver-460

$ sudo reboot

Reboot after installation is complete,use the nvidia-smi command to confirm whether the installation is complete.

$ nvidia-smi

$ sudo apt remove gdm3

Install CUDA

https://developer.nvidia.com/cuda-downloads

$ wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin

$ sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600

$ sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub

$ sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /"

$ sudo apt-get update

$ sudo apt-get -y install cuda

Add the following lines to the ~/.bashrc

# cuda

export PATH=/usr/local/cuda-11.2/bin${PATH:+:${PATH}}

export LD_LIBRARY_PATH=/usr/local/cuda-11.2/lib64\

${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

Reload ~/.bashrc

$ source ~/.bashrc

Test whether the installation is complete

$ nvcc -V nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2021 NVIDIA Corporation Built on Thu_Jan_28_19:32:09_PST_2021 Cuda compilation tools, release 11.2, V11.2.142 Build cuda_11.2.r11.2/compiler.29558016_0

Official documents

Install cuDNN

$ cudnn_version=8.1.0.77

$ cuda_version=cuda11.2

$ OS=ubuntu2004

Enable the repository

$ wget https://developer.download.nvidia.com/compute/cuda/repos/${OS}/x86_64/cuda-${OS}.pin



$ sudo mv cuda-${OS}.pin /etc/apt/preferences.d/cuda-repository-pin-600

$ sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/${OS}/x86_64/7fa2af80.pub

$ sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/${OS}/x86_64/ /"

$ sudo apt-get update

Install the cuDNN library

$ sudo apt-get install libcudnn8=${cudnn_version}-1+${cuda_version}

$ sudo apt-get install libcudnn8-dev=${cudnn_version}-1+${cuda_version}

Install Docker

Update the apt package index and install packages to allow apt to use a repository over HTTPS

$ sudo apt-get update

$ sudo apt-get install \

apt-transport-https \

ca-certificates \

curl \

gnupg



Add Docker’s official GPG key

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg — dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Use the following command to set up the stable repository

$ echo \

"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \

$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install docker engine

$ sudo apt-get update

$ sudo apt-get install docker-ce docker-ce-cli containerd.io

Manage Docker as a non-root user

$ sudo usermod -aG docker $USER

Verify that you can run docker commands without sudo

$ docker run hello-world

Install Nvidia Docker

$ 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 $ sudo apt install -y nvidia-container-toolkit

$ sudo reboot

Official documents

https://nvidia.github.io/nvidia-docker/

https://github.com/NVIDIA/nvidia-docker/wiki/Installation-(Native-GPU-Support)