Author: mt

Tags: Ubuntu, Install, Linux

Install Ubuntu 18.04 for development

注意,此文档中:

  • 部分内容可能已经过时

  • 部分链接可能已经失效

  • 有些步骤对普通开发者没有必要

强烈建议:

  • 尝试更新版本的ubuntu,至少是20.04

  • 弄清楚每一步是在干嘛

  • 使用ubuntu而不是windows进行开发

  • 使用命令行而不是GUI(至少一开始)

以及:

  • 此文档原文是英文,我懒得翻译了,大家应该学会适应英文的技术文档qwq

Create some free space (50GB or more) for Ubuntu

There are several ways to do this. We’ll list them from easy to hard.

  1. Get a new clean hard disk.

  2. Find a disk with enough space and GPT partition table. You can find the partition table type in ‘’diskmgmt.msc’‘, by right clicking a disk and select’‘Property’‘. Then use’‘Shrink Volume’’ to create free space. Read https://www.tecmint.com/install-ubuntu-alongside-with-windows/ for this approach.

  3. Find a disk with enough space and MBR partition table. Then use the Windows MBR2GPT tool to convert it to GPT. This is not recommended.

Install Ubuntu

  1. Use Ubuntu USB image to start the installation wizard. Possible issues and solutions:

    1. Your machine directly starts Windows. Solution: Use the boot menu or BIOS option(usually by pressing F12 or F2 during start up). Select ‘’UEFI: Kingston Data Traveller’’.
    2. After selecting ‘’Install Ubuntu’’, the screen goes black or purple. Solution: Connect to only one monitor. Use HDMI/VGA/DVI cable instead of DP cable.
  2. Select language and keyboard layout.

  3. Select ‘’Normal Installation’‘. Don’t check’‘Download updates’‘. Don’t check’‘Install third-party software’’.

  4. Select ‘’Something else’’.

  5. If you’re using a new disk, select the disk and click ‘’New Partition Table’‘. All space on this disk will become’‘free space’‘. If you’re using a shrinked volume, find the’‘free space’’ you just created. Possible issues and solutions:

    1. The free space is marked ‘’unusable’’. Solution: Check the disk partition table type and convert it to GPT.
  6. Select the ‘’free space’‘, create following partitions by clicking’‘+’’.

    1. = 500MB, EFI

    2. = 20GB, ext4, /boot

    3. = 30GB, ext4, /

    4. Optionally, >= 30G, swap
    5. Optionally, >= 500G, ext4, /usr/local
    6. Optionally, >= 1T, ext4, /home
    7. Optionally, arbitary size, ext4, /opt
  7. Double check your changes to the disk. This may erase all your data.

  8. Select timezone, set user name, computer name, password, and start installation.

  9. Wait until Ubuntu prompts to restart. If dual boot is not working, you may need to change your BIOS settings. Read https://www.tecmint.com/install-ubuntu-alongside-with-windows/.

  10. Open ‘’Software & Updates’’.

  11. Goto ‘’Ubuntu Software’‘, select’‘Other’’ for ‘’Download from’’, choose mirrors.tuna.tsinghua.edu.cn.

  12. ‘’sudo apt update && sudo apt upgrade’’.

  13. If you are using an NVidia graphics card, goto ‘’Additional Drivers’‘, select’‘Using NVIDIA driver metapackage from nvidia-driver-470’’ or the latest nvidia driver, click ‘’Apply Changes’’, enter your password when prompted, wait until the installation finishes and you are prompted to restart the machine.

  14. Restart. You can connect to multiple monitors and/or use DP cable now.

Install CUDA (Optional)

  1. 下载cuda(你需要根据版本修改对应链接) http://developer.download.nvidia.com/compute/cuda/10.1/Prod/localinstallers/cuda10.1.243418.87.00linux.run.

  2. 安装

sudo apt install gcc
chmod +x cuda_10.1.243_418.87.00_linux.run && sudo ./cuda_10.1.243_418.87.00_linux.run
  1. (注意不要选择安装驱动!!!)In the shell ui, ‘’Continue’’ -> accept -> Deselect Driver -> ‘’Install’’

  2. Add following lines to ~/.bashrc:

export PATH=/usr/local/cuda-10.1/bin:/usr/local/cuda-10.1/NsightCompute-2019.1${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export CUDA_PATH=/usr/local/cuda-10.1
  1. Download https://developer.nvidia.com/designworks/videocodecsdk/downloads/v9.1 and extract <VideoCodecSDK_9.1>/include/* to /usr/local/cuda-10.1/include/.

  2. Restart shell and ‘’sudo ldconfig’’.

Install Conda and create Python environment (Optional)

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

sh Miniconda3-py39_4.10.3-Linux-x86_64.sh

Download and install C++ libraries (Optional)

Install gcc-8

以及各种乱七八糟的依赖

sudo apt install gcc-8 g++-8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 100 --slave /usr/bin/g++ g++ /usr/bin/g++-7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 200 --slave /usr/bin/g++ g++ /usr/bin/g++-8
sudo update-alternatives --config gcc

sudo apt install clang git tar unzip ffmpeg libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libavresample-dev libpng-dev libturbojpeg0-dev libtiff-dev libxxf86vm1 libxxf86vm-dev libxi-dev libxrandr-dev libegl1-mesa-dev libgl1-mesa-dev libglu1-mesa-dev libgles2-mesa-dev libglfw3-dev libtbb-dev libgoogle-glog-dev libatlas-base-dev libsuitesparse-dev libgmp-dev libmpfr-dev libzmqpp-dev libassimp-dev libfmt-dev libomp-dev xorg-dev autoconf libtool libxcb-xinput0

sudo apt install libxcb-image0-dev libxcb-icccm4-dev libxcb-icccm4-dev libxcb-render-util0-dev libxcb-keysyms1-dev libxcb-xinerama0-dev libxcb-xinput-dev libxcb-util-dev libxcb-xkb-dev

Install cmake

sudo apt install cmake

或者用python3的pip安装(没想到吧,pip上也有cmake,而且版本更新)

pip install cmake

Install conan (Optional)

conan 是一个 c++ 包管理工具,如果你不知道它是啥,你多半用不到

conda create -n conan python=3.7
conda activate conan
conda install conan -c conda-forge

Generate default profile:

conan profile new default --detect

… and if you are using gcc on Ubuntu

conan profile update settings.compiler.libcxx=libstdc++11 default

使用等略