[The most complete in history] Reinstall the basic environment configuration of ubuntu20.04 system

I recently bought a new computer and reinstalled ubuntu to play deep learning. After two days of pitfalls, the summary is as follows

1. Reinstall the system (U disk method)

ubuntu20.04 image file download address:

Download the .iso image file on the ubuntu official website, and then use the UltralSO software to make a system boot disk. You can download the UltralSO software directly from its official website.

1. File - Open - Select the iso file

2. Boot - write hard disk image

Click Write. This process will last for a few minutes, and the message box will display "burning complete", and a system disk will be created.

After the system disk is made, insert the prepared system disk into the computer that needs to reinstall the system, and keep pressing the ESC key to enter the BIOS mode when turning on the computer.

 In the Boot Priority, select the U disk to start, and enter the next step, you can enter the ubuntu installation steps.

 This step is selected according to your own needs. Option 1 is suitable for reinstalling ubuntu, option 2 is suitable for dual systems, and option 3 is similar to 1, which is to clear all the original system files. These few English explanations are not difficult.

 At this point, the system installation is complete. Unplug the U disk and restart the computer to enter the system.

 The first thing after the installation is complete, first change the source of apt. The specific operation is as follows:

sudo /etc/apt/sources.list /etc/apt/sources.list.back
sudo gedit /etc/apt/sources.list

 Write the following content in the sources.list file (add Tsinghua source on the basis of the original)


# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse


#deb cdrom:[Ubuntu 22.04 LTS _Jammy Jellyfish_ - Release amd64 (20220419)]/ jammy main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://cn.archive.ubuntu.com/ubuntu/ jammy main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://cn.archive.ubuntu.com/ubuntu/ jammy universe
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy universe
deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates universe
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://cn.archive.ubuntu.com/ubuntu/ jammy multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://cn.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu jammy-security main restricted
# deb-src http://security.ubuntu.com/ubuntu jammy-security main restricted
deb http://security.ubuntu.com/ubuntu jammy-security universe
# deb-src http://security.ubuntu.com/ubuntu jammy-security universe
deb http://security.ubuntu.com/ubuntu jammy-security multiverse
# deb-src http://security.ubuntu.com/ubuntu jammy-security multiverse

# This system was installed using small removable media
# (e.g. netinst, live or single CD). The matching "deb cdrom"
# entries were disabled at the end of the installation process.
# For information about how to configure apt package sources,
# see the sources.list(5) manual.

# deb [arch=amd64] http://archive.ubuntu.com/ubuntu focal main universe

Save and exit, update the source

sudo apt update
sudo apt upgrade

 2. Graphics card driver installation

Go to nvidia official website to download the graphics card driver, because I use 3080ti here, so I choose 3080ti, download address: official driver | NVIDIA

After the download is complete, it is a runfile

There are two problems here:

1. Driver installation requires gcc and make, so first check whether your computer has installed gcc and make

sudo apt install gcc
Sudo apt install make

2. Because there is a nouveau driver in our system, we must first disable nouveau and then install the nvidia driver.

sudo gedit/etc/modprobe.d/blacklist.conf

Add two lines at the end of the file

blacklist nouveau
options nouveau modeset=0

make it effective 

sudo update-initramfs -u

Then restart reboot 

Install the driver after reboot

# 替换为自己的驱动即可
sudo sh NVIDIA-Linux-x86_64-515.57.run

 

Select Yes. After the installation is complete, verify whether the driver installation is successful, and the graphics card information will appear.

nvidia-smi

Pit stepped on:

The first thing I installed was ubuntu22.04. When installing the nvidia driver for that version, an error was prompted. The error message was: you appear to be running an x ​​server please exit x before installing. This is because the system itself has a driver for display, there are two solutions

  1. Disable lightdm, enter the command line mode, and then install the system
  2. Install a todesk on the computer, use another computer to remotely control this computer, and install the driver remotely. (Personal test is feasible)

Another pitfall is that the gcc version of ubuntu22.04 is gcc-11, and the gcc version of ubuntu20.04 is gcc-9. Before installation, you should consider your own needs. If you need to use paddlepaddle, do not install ubuntu22.04.

3. cuda and cudnn installation 

 cuda download address: CUDA Toolkit Archive | NVIDIA Developer

Select a cuda version to install, download the corresponding runfile file, and pay attention to matching with the driver version. For details, refer to  the basic environment installation configuration (conda) of the newly installed Ubuntu system

I chose cuda11.6 here 

 

# 安装cuda
sudo sh cuda_11.6.0_510.39.01_linux.run

 Regular installation is enough, because the nvidia driver has been installed in the previous step, so when you choose to install components, you need to remove the Driver option and continue the installation to complete.

Next configure the system path of cuda, first open the .bashrc file in the home directory

sudo gedit ~/.bashrc

 Add the following at the end of the file:

# added install cuda
export PATH=/usr/local/cuda-11.6/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.6/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

Save and close the file to complete the configuration. Update environment:

source ~/.bashrc

 Finally check whether cuda is installed successfully

nvcc -V

 

After the cuda installation is complete, the next step is the installation of cudnn

Enter the official website https://developer.nvidia.com/rdp/cudnn-download

Note that to download cudnn, you must register first, and you can download it after registering and logging in.

 Unzip the downloaded .tar.xz file of cudnn, name it cudnn (you are free), and perform the following operations

sudo cp cudnn/include/cudnn.h /usr/local/cuda/include/
sudo cp cudnn/include/cudnn_version.h /usr/local/cuda/include
sudo cp cudnn/lib64/libcudnn* /usr/local/cuda/lib64/ -d
sudo chmod a+r /usr/local/cuda/include/cudnn.h
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*

Then verify that cudnn is installed successfully

cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2

 

At this point, cuda and cudnn are installed.

4. Conda manages the python environment

Go to the mirror of Tsinghua University to download the annaconda installation package and download the sh file of anaconda.

Index of /anaconda/archive/ | Tsinghua University Open Source Software Mirror Station | Tsinghua Open Source Mirror

bash Anaconda3-5.3.1-Linux-x86_64.sh
# 配置conda环境变量
sudo gedit ~/.bashrc

Add at the end of the file

# 选择自己的anaconda安装路径
export PATH=”/home/elvis/anaconda3/bin:$PATH”

Update it:

source ~/.bashrc

Finally, enter conda -V to check, if the version information of conda appears, the installation is successful.

After the installation is complete, remember to update the pip source, which provides services for pip install downloads.

cd ~                   # 进入家目录 
mkdir .pip          # 新建.pip隐藏文件夹
cd .pip                  # 进入.pip文件夹
touch pip.conf   # 新建pip.conf文件
sudo gedit pip.conf      # 用gedit编辑pip.conf文件

Write in pip.conf

[global]
 
index-url=https://pypi.tuna.tsinghua.edu.cn/simple
 
timeout = 6000
 
[install]
 
trusted-host=pypi.tuna.tsinghua.edu.cn
 
disable-pip-version-check = true

 Save and exit.

Finally, post a QR code to make the rich brothers happy.

 

 

 

Guess you like

Origin blog.csdn.net/Eyesleft_being/article/details/126020113