Debian11安装gcc-5和g++-5
背景
在Debian11系统编译C/C++项目时,需要用到gcc-5和g++-5,而在Debian11系统上而且无法通过apt直接安装gcc-5和g++-5。
在Debian11系统上安装gcc-5和g++-5
安装依赖
sudo apt install libncurses-dev
sudo apt install bison
sudo apt install flex
sudo apt install build-essential
wget http://mirrors.ustc.edu.cn/debian/pool/main/g/gcc-6/gcc-6-base_6.3.0-18%2Bdeb9u1_amd64.deb
dpkg -i gcc-6-base_6.3.0-18+deb9u1_amd64.deb
wget http://mirrors.ustc.edu.cn/debian/pool/main/g/gcc-6/libubsan0_6.3.0-18+deb9u1_amd64.deb
dpkg -i libubsan0_6.3.0-18+deb9u1_amd64.deb
wget http://mirrors.ustc.edu.cn/debian/pool/main/g/gcc-6/libcilkrts5_6.3.0-18%2Bdeb9u1_amd64.deb
dpkg -i libcilkrts5_6.3.0-18+deb9u1_amd64.deb
安装gcc-5和g++-5
安装完相关依赖后,下载gcc-5和g++-5的deb文件,使用dpkg安装。
- 创建一个文件夹,用来存放下载的deb文件
mkdir g5_debs
cd g5_debs
- 下载deb文件
wget http://archive.ubuntu.com/ubuntu/pool/universe/g/gcc-5/cpp-cpp-55_5.5.0-12ubuntu1_amd64.deb
wget http://archive.ubuntu.com/ubuntu/pool/universe/g/gcc-5/g++-5_5.5.0-12ubuntu1_amd64.deb
wget http://archive.ubuntu.com/ubuntu/pool/universe/g/gcc-5/gcc-5_5.5.0-12ubuntu1_amd64.deb
wget http://archive.ubuntu.com/ubuntu/pool/universe/g/gcc-5/gcc-5-base_5.5.0-12ubuntu1_amd64.deb
wget http://archive.ubuntu.com/ubuntu/pool/universe/g/gcc-5/libasan2_5.5.0-12ubuntu1_amd64.deb
wget http://archive.ubuntu.com/ubuntu/pool/universe/g/gcc-5/libgcc-5-dev_5.5.0-12ubuntu1_amd64.deb
wget http://archive.ubuntu.com/ubuntu/pool/universe/g/gcc-5/libmpx0_5.5.0-12ubuntu1_amd64.deb
wget http://archive.ubuntu.com/ubuntu/pool/universe/g/gcc-5/libstdc++-5-dev_5.5.0-12ubuntu1_amd64.deb
- 安装所有deb包
sudo dpkg -i *.deb
版本管理
gcc版本管理
查看已安装的gcc:
# ls -lha /usr/bin/gcc*
lrwxrwxrwx 1 root root 21 10月 20 13:51 /usr/bin/gcc -> /etc/alternatives/gcc
lrwxrwxrwx 1 root root 23 1月 10 2021 /usr/bin/gcc-10 -> x86_64-linux-gnu-gcc-10
-rwxr-xr-x 1 root root 887K 4月 12 2018 /usr/bin/gcc-5
lrwxrwxrwx 1 root root 9 1月 12 2021 /usr/bin/gcc-ar -> gcc-ar-10
lrwxrwxrwx 1 root root 26 1月 10 2021 /usr/bin/gcc-ar-10 -> x86_64-linux-gnu-gcc-ar-10
-rwxr-xr-x 1 root root 31K 4月 12 2018 /usr/bin/gcc-ar-5
lrwxrwxrwx 1 root root 9 1月 12 2021 /usr/bin/gcc-nm -> gcc-nm-10
lrwxrwxrwx 1 root root 26 1月 10 2021 /usr/bin/gcc-nm-10 -> x86_64-linux-gnu-gcc-nm-10
-rwxr-xr-x 1 root root 31K 4月 12 2018 /usr/bin/gcc-nm-5
lrwxrwxrwx 1 root root 13 1月 12 2021 /usr/bin/gcc-ranlib -> gcc-ranlib-10
lrwxrwxrwx 1 root root 30 1月 10 2021 /usr/bin/gcc-ranlib-10 -> x86_64-linux-gnu-gcc-ranlib-10
-rwxr-xr-x 1 root root 31K 4月 12 2018 /usr/bin/gcc-ranlib-5
可以看到目前有5和10两个版本,5是在“安装gcc-5和g++-5”这一步安装的,10则是在“安装依赖”这一步执行sudo apt install build-essential
时自动安装的。
接下来,我们使用update-alternatives
来管理gcc版本。使用如下命令为刚安装好的gcc 5增加可选项(此处应根据自己新安装的gcc版本来进行操作,最后的30表示优先级,数字越大优先级越高,随便设一个就行):
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 30
查看当前gcc版本:
# gcc --version
gcc (Ubuntu 5.5.0-12ubuntu1) 5.5.0 20171010
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
g++版本管理
查看已安装的g++:
# ls -lha /usr/bin/g++*
lrwxrwxrwx 1 root root 21 10月 20 13:51 /usr/bin/g++ -> /etc/alternatives/g++
lrwxrwxrwx 1 root root 23 1月 10 2021 /usr/bin/g++-10 -> x86_64-linux-gnu-g++-10
-rwxr-xr-x 1 root root 891K 4月 12 2018 /usr/bin/g++-5
为g++-5增加可选项:
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 30
查看当前g++版本:
# g++ --version
g++ (Ubuntu 5.5.0-12ubuntu1) 5.5.0 20171010
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
【完】