最近这段时间装了好多次ubuntu,积累了非常多经验,为了不在下一次(希望没有)装的时候还要google各种教程,遂写下这篇文档。(内容大部分来源于 rm.cv.radar2025 的INSTALL.md,不过很多也算是我写的/)

Installation

Install ubuntu20.04

制作启动盘

ubuntu20.04.06LTS下载镜像,使用rufus工具刻录至U盘

安装

  1. 插入启动盘并重启计算机。
  2. 在启动时按下相应的键(例如 F12、Esc、F2 等)进入 BIOS 设置,选择从 U 盘启动。
  3. 选择 "Install Ubuntu" 选项,按照屏幕上的提示进行安装。
  4. 在安装过程中,选择安装类型(例如 "Erase disk and install Ubuntu" 或 "Install Ubuntu alongside Windows",这两项一般不选,选择else自定义分区)。
  5. 设置时区、键盘布局和用户信息。
  6. 安装完成后,重启计算机并移除 U 盘。

配置系统

安装完成后,可以进行一些基本的系统配置:

  1. 配置交大校园网/交大vpn
    可以在sjtu-networksjtu-vpn里查看配置方法。
  2. 在软件&更新进行换源
  3. 更新系统:
    1
    2
    sudo apt update
    sudo apt upgrade -y
  4. 安装常用软件,大部分可以在浏览器下载deb安装包
    1
    2
    3
    4
    # 下载deb包后,安装指令如下
    sudo dpkg -i xxxx.deb
    # 安装一些其他的常用工具
    sudo apt install -y vim git curl

Disable apt autoremove (optional)

这一步是因为当环境变得复杂,autoremove会造成非常重大的后果,导致系统崩坏(别问我是怎么知道的)

1
2
echo 'APT::Get::AutomaticRemove "false";' | sudo tee -a /etc/apt/apt.conf.d/01autoremove
echo 'APT::Get::AutomaticRemove "false";' | sudo tee -a /etc/apt/apt.conf.d/00aptitude

Install Nvidia driver

1
2
3
4
5
6
7
8
9
10
echo "blacklist nouveau" | sudo tee -a /etc/modprobe.d/blacklist.conf
echo "options nouveau modeset=0" | sudo tee -a /etc/modprobe.d/blacklist.conf
sudo update-initramfs -u
reboot
lsmod | grep nouveau # if no response,then success
sudo apt install lightdm #optional
sudo add-apt-repository ppa:graphics-drivers/ppa
# 做到这一步其实就可以不用继续了,因为在安装cuda时会自动安装对应的驱动
# 如果还是想安装驱动,推荐使用软件&更新,或者如下命令
sudo ubuntu-drivers autoinstall

Install CUDA and cuDNN

Install CUDA:

1
2
3
4
5
6
7
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
wget https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda-repo-ubuntu2004-12-4-local_12.4.0-550.54.14-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2004-12-4-local_12.4.0-550.54.14-1_amd64.deb
sudo cp /var/cuda-repo-ubuntu2004-12-4-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda-toolkit-12-4

Download the cuDNN archive from cudnn archive. Since the download link may redirect, you can either locate the actual link for wget or curl or download it in Windows and copy it into WSL using VS Code.

Extract and install cuDNN:

1
2
3
4
cd ~ && tar -xvf cudnn-linux-x86_64-8.9.7.29_cuda12-archive.tar.xz
sudo cp cudnn-linux-x86_64-8.9.7.29_cuda12-archive/include/* /usr/local/cuda-12.4/include
sudo cp cudnn-linux-x86_64-8.9.7.29_cuda12-archive/lib/* /usr/local/cuda-12.4/lib64
rm -rf cudnn-linux-x86_64-8.9.7.29_cuda12-archive.tar.xz cudnn-linux-x86_64-8.9.7.29_cuda12-archive/

If you encounter the error:

1
/usr/local/cuda/lib64/libcudnn*.so.* is not a symbolic link

You can use this script to fix the links:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/bash

for file in /usr/local/cuda/lib64/libcudnn*.so.*; do
next_file=$(echo $file | sed -E 's/\.[0-9]+$//')

while [[ ! -e $next_file ]]; do
next_file=$(echo $next_file | sed -E 's/\.[0-9]+$//')
if [[ $next_file == $file ]]; then
echo "No link for $file"
break
fi
done
echo "Linking $file -> $next_file"
# sudo ln -sf $file $next_file
done

Uncomment the ln command only after verifying the links are correct.

配置项目环境 (适用于rm.cv.radar2025)

Update cmake

1
2
3
4
5
6
snap install cmake
echo "export PATH=$PATH:/snap/bin" >> ~/.bashrc
# 检查是否安装成功
source ~/.bashrc
which cmake
# 如果返回snap路径,则成功

Install OpenCV

Clone and build OpenCV:

1
2
3
4
git clone git@github.com:opencv/opencv ~/opencv/opencv
git clone git@github.com:opencv/opencv_contrib.git ~/opencv/opencv_contrib
cd ~/opencv/opencv
mkdir build && cd build

Run the following cmake command:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D WITH_CUBLAS=1 \
-D WITH_CUDA=ON \
-D WITH_CUDNN=ON \
-D WITH_NVCUVENC=OFF
-D WITH_NVCUVID=OFF
-D OPENCV_DNN_CUDA=ON \
-D CUDA_ARCH_BIN=8.9 \
-D BUILD_EXAMPLES=ON ..

Build and install OpenCV:

1
make -j$(nproc) && sudo make install

Install ROS

Use this command to install ROS:

1
wget http://fishros.com/install -O fishros && . fishros

Install Livox ROS Driver

Install Livox SDK and ROS driver:

1
2
3
4
5
mkdir -p ~/workspace && cd ~/workspace
git clone https://github.com/Livox-SDK/Livox-SDK.git
cd Livox-SDK && mkdir build && cd build
cmake ..
make -j$(nproc) && sudo make install

For the ROS driver:

1
2
3
4
cd ~/workspace && git clone https://github.com/Livox-SDK/livox_ros_driver.git ws_livox/src
cd ws_livox
catkin_make
echo "source ~/workspace/ws_livox/devel/setup.bash" >> ~/.bashrc && source ~/.bashrc

Install TensorRT

Download and extract TensorRT:

1
2
3
4
5
cd ~ && wget https://developer.nvidia.com/downloads/compute/machine-learning/tensorrt/secure/8.6.1/tars/TensorRT-8.6.1.6.Linux.x86_64-gnu.cuda-12.0.tar.gz
tar -xzvf TensorRT-8.6.1.6.Linux.x86_64-gnu.cuda-12.0.tar.gz
sudo mv TensorRT-8.6.1.6 /opt/TensorRT-8.6.1.6
echo "export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/opt/TensorRT-8.6.1.6/lib" >> ~/.bashrc
source ~/.bashrc

Install MVS

Install MVS from hikrobotics

1
2
cd /opt/MVS/lib/64
mv libusb-1.0.so.0 libusb-1.0.so.0.bak

Install needed python packages

1
pip install flask flask_socketio flask_cors

Install Open3d

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
sudo apt update
sudo apt install -y build-essential \
cmake git libeigen3-dev libpng-dev \
libjpeg-dev libtiff-dev libdcmtk-dev \
libvtk6-dev python3-pybind11 \
libopenblas-dev liblapack-dev \
libflann-dev
sudo apt-get install libc++-7-dev
sudo apt-get install libc++abi-7-dev
cd ~/Documents
git clone https://github.com/isl-org/Open3D.git
cd Open3D
mkdir build && cd build
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_CUDA_MODULE=ON \
-DBUILD_PYTHON=ON \
-DBUILD_EXAMPLES=ON \
-DBUILE_ISPC_MOUDLE=ON \
-DCMAKE_CUDA_ARCHITECTURES=89 \
..
make -j8
sudo make install

Install vue

1
2
sudo apt install nodejs npm
sudo npm install -g vue-cli

Install PCL

1
2
sudo apt-get update
sudo apt-get install ros-noetic-pcl-ros ros-noetic-pcl-conversions

Install apriltag

1
2
3
4
5
6
7
8
sudo apt-get update
sudo apt-get install libapriltag-dev
git clone https://github.com/AprilRobotics/apriltag.git ~/catkin_ws/src/apriltag
git clone https://github.com/AprilRobotics/apriltag_ros.git ~/catkin_ws/src/apriltag_ros
cd ~/catkin_ws
rosdep install --from-paths src --ignore-src -r -y
catkin build
echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc

Install fmt

1
2
3
4
5
6
7
8
9
sudo apt-get install fmt.dev
git clone https://ghproxy.com/https://github.com/fmtlib/fmt.git
cd fmt/
git checkout 11.0.2
mkdir build
cd build
cmake -DFMT_ENABLE_STRING_VIEW=ON -DCMAKE_CXX_STANDARD=17 -DCMAKE_POSITION_INDEPENDENT_CODE=ON ..
make -j${proc}
sudo make install