Just for record Ubuntu20.04 Setup

0x00 apt换cn源

Optional
ustc
aliyun
163

1
2
sudo apt update
sudo apt upgrade -y

0x01 apt install

1
2
3
4
5
6
sudo apt install \
git git-lfs wget curl vim \
language-pack-zh-hans tree \
ncdu htop tmux nnn nload \
ca-certificates gpg \
net-tools make gcc g++

0x02 fonts

Optional
I use Font:‘Meslo LG L Regular for Powerline’

1
2
git clone git@github.com:powerline/fonts.git
sh fonts/install.sh

0x03 install zsh & ohmyzsh

install zsh

1
sudo apt install zsh

install ohmyzsh

1
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

ohmyzsh plugins

1
2
3
4
5
pushd .oh-my-zsh
for plug in {zsh-autosuggestions,zsh-syntax-highlighting,zsh-completions}; do
git clone git@github.com:zsh-users/$plug.git ~/.oh-my-zsh/custom/plugins/$plug
done;
popd

manually change default $SHELL

1
chsh -s /usr/bin/zsh

重启终端后可以看到

1
2
$ echo $SHELL
/usr/bin/zsh

clipboard

Optional GUI required
install dependency, xclip on ubuntu

pbcopy, pbpaste (macOS)
cygwin (Windows running Cygwin)
wl-copy, wl-paste (if $WAYLAND_DISPLAY is set)
xsel (if $DISPLAY is set)
xclip (if $DISPLAY is set)
lemonade (for SSH) https://github.com/pocke/lemonade
doitclient (for SSH) http://www.chiark.greenend.org.uk/~sgtatham/doit/
win32yank (Windows)
tmux (if $TMUX is set)

Usage:

1
2
3
4
5
6
<command> | clipcopy  # copy from stdout
clipcopy <file> # copy file content

clippaste # paste to stdout, same to CTRL+C
clippaste | <command> # paste to pipe
clippaste > <file> # paste contents to a file

0x04 LLVM stuff

LLVM download package

1
2
3
4
5
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -

sudo apt update

sudo apt install clangd-17 clang-format-17 libomp-17-dev

0x05 CMake

Install from apt repo

1
2
3
4
5
6
7
8
9
10
11
12
13
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null \
| gpg --dearmor - \
| sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null

echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ focal main' \
| sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null

sudo apt-get update

# install 3.25.2 (CLion not support 3.26 yet)
sudo apt install cmake{,-data,-qt-gui}=3.25.2-0kitware1ubuntu20.04.1

sudo apt-mark hold cmake cmake-data cmake-qt-gui

0x06 NVIDIA stuff

Driver

driver装最新的就行,高版本兼容低版本
skip this section on WSL, nvidia driver on windows already done this

  1. download a xxx.run file
  2. install NVIDIA driver bash NVIDIA-Linux-x86_64-530.41.03.run
  3. reboot
  4. install (cuda)[https://developer.nvidia.com/cuda-toolkit-archive]

NVIDIA Docker

Work on Ubuntu,Debian, WSL as well.

First install Docker

Install Docker Engine

WSL

install Windows Docker-Desktop

Linux

Example for Ubuntu>18.04:

install from apt repo

Install using the repository

1
2
3
4
5
6
7
8
9
10
11
12
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Install nvidia-docker2

official doc

Note that in some cases the downloaded list file may contain URLs that do not seem to match the expected value of distribution which is expected as packages may be used for all compatible distributions. As an examples:

  • For distribution values of ubuntu20.04 or ubuntu22.04 the file will contain ubuntu18.04 URLs
  • For a distribution value of debian11 the file will contain debian10 URLs
1
2
3
4
5
6
7
8
9
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)

curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-docker-keyring.gpg

curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-docker-keyring.gpg] https://#g' | sudo tee /etc/apt/sources.list.d/nvidia-docker.list

sudo apt-get update

sudo apt-get install -y nvidia-docker2

Update daemon.json

Edit docker config

1
sudo vim /etc/docker/daemon.json
  • set default-runtime to nvidia.
  • set data root of docker contents.

Sample:

1
2
3
4
5
6
7
8
9
10
{
"runtimes": {
"nvidia": {
"path": "nvidia-container-runtime",
"runtimeArgs": []
}
},
"default-runtime":"nvidia",
"data-root":"/opt/docker_root"
}

Then, restart docker

1
systemctl restart docker # or daemon reload

Test Nvidia Docker

Test with official docker images:

1
2
3
4
5
docker run -it --rm nvcr.io/nvidia/k8s/cuda-sample:devicequery-cuda11.7.1-ubuntu20.04

docker run -it --rm nvcr.io/nvidia/k8s/cuda-sample:vectoradd-cuda11.7.1-ubi8

docker run nvcr.io/nvidia/k8s/cuda-sample:nbody -benchmark -numbodies=1024

CUDA toolkit

Linux

official doc

Cuda install .deb file contains a driver, so choose a specific package to install meta package

CUDNN

download from tar file

doc

1
2
3
4
tar -xvf cudnn-linux-x86_64-8.x.x.x_cudaX.Y-archive.tar.xz
sudo cp cudnn-*-archive/include/cudnn*.h /usr/local/cuda/include
sudo cp -P cudnn-*-archive/lib/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*
other

libcudnn不会和cudatoolkit一起安装,nvidia提供下载页面,下载后copy到cuda的lib目录下。对应docker label:nvidia/cuda:xxxx-cudnn-xxx

有一个trick:pip 安装的torch中带一个libcudnn,在torch的安装位置的lib里,如/usr/lib/python3.10/site-packages/torch/lib。不然torch的gpu版的体积也不用这么大。

还可以使用pip安装。如pip install nvidia-cudnn-xxxxx

WSL

WSL CUDA

原因:
WSL nvidia-container-cli 需要用 /usr/lib/wsl/lib下的东西,而且都是copy,不可以是link
WSL 内ldconfig 需要用 {xxx}.so link to file {xxx}.so.1.1

issue and solution

WSL内/usr/lib/wsl/lib是auto mount%SYSTEMROOT%\System32\lxss\lib的,把这个automount关掉,修改/etc/wsl.conf

1
2
[automount]
ldconfig = false

创建link:

1
2
mkdir /usr/lib/wsl/lib2
ln -s /usr/lib/wsl/lib/* /usr/lib/wsl/lib2

然后修改/etc/ld.so.conf.d/ld.wsl.conf,让ldconfig全用link的

1
/usr/lib/wsl/lib2

最后重新启动wsl。

Post-installation Actions

doc

set path
1
2
3
export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64\
${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
Verify the Installation

check version

1
cat /proc/driver/nvidia/version

run samples from https://github.com/nvidia/cuda-samples

0x07 Setup python env with conda

see Install MiniConda

0x08 OpenCL

WSL不支持Opencl No OpenCL platforms reported

1
2
3
4
5
6
7
8
9
10
11
12
13
sudo apt install ocl-icd-opencl-dev \
libx11-dev \
libxcb1-dev \
libgles-dev \
libglx-dev \
libomp-dev \
libglfw3-dev \
libglew-dev \
libx264-dev \
libx265-dev \
nasm \
clinfo

Check status:

1
clinfo

0x09 OpenCV

1
2
3
4
5
6
7
8
9
git clone -b 4.5.5 --depth 1 git@github.com:opencv/opencv.git
pushd opencv
mkdir -p build
pushd build
cmake ..
make -j16
sudo make install
popd
popd

0x0a Gnome Extention

简单记录几个我在用的extension

Install

Documentation

1
sudo apt-get install chrome-gnome-shell gnome-tweaks gnome-shell-extensions

Chrome extension: Gnome shell integration

My Extensions: