Install gcc-7, g++-7 on ubuntu 22.04

Install gcc-7, g++-7 on ubuntu 22.04

1. Install gcc-7

1.1 Add mirror

(base) root@FIB:~# vim /etc/apt/sources.list
(base) root@FIB:~# tail -1 /etc/apt/sources.list
deb [arch=amd64] http://archive.ubuntu.com/ubuntu focal main universe

1.2 Update mirror

(base) root@FIB:~# apt-get update

1.3 Specified version installation

(base) root@FIB:~# apt-get -y install gcc-7 g++-7

2. Configuration priority

2.1 Configure the priority of gcc and g++ versions

#配置gcc版本的优先级
(base) root@FIB:~# update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 50
(base) root@FIB:~# update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 30
(base) root@FIB:~# update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 20
#配置g++版本的优先级
(base) root@FIB:~# update-alternatives  --install /usr/bin/g++ g++ /usr/bin/g++-7 50
(base) root@FIB:~# update-alternatives  --install /usr/bin/g++ g++ /usr/bin/g++-10 30
(base) root@FIB:~# update-alternatives  --install /usr/bin/g++ g++ /usr/bin/g++-11 20

2.2 Switch the required gcc version, the default is 0 option. After entering the required gcc version serial number, you can switch successfully (g++ is the same)

(base) root@FIB:~/cu110# update-alternatives --config gcc
有 3 个候选项可用于替换 gcc (提供 /usr/bin/gcc)。

  选择       路径           优先级  状态
------------------------------------------------------------
* 0            /usr/bin/gcc-7    50        自动模式
  1            /usr/bin/gcc-10   30        手动模式
  2            /usr/bin/gcc-11   20        手动模式
  3            /usr/bin/gcc-7    50        手动模式

要维持当前值[*]请按<回车键>,或者键入选择的编号:

2.3 Check and find that it has been switched (g++ is the same)

(base) root@FIB:~/cu110# update-alternatives --query gcc
Name: gcc
Link: /usr/bin/gcc
Status: manual
Best: /usr/bin/gcc-7
Value: /usr/bin/gcc-7

Alternative: /usr/bin/gcc-10
Priority: 30

Alternative: /usr/bin/gcc-11
Priority: 20

Alternative: /usr/bin/gcc-7
Priority: 50

Guess you like

Origin blog.csdn.net/weixin_43279138/article/details/126728005