Debian 安装 GCC、G++、GDB

提示

GCC 4.8.1,这是该编译器由 C 语言实现转向 C++ 实现(4.8 版本)后的首次升级,也是第一个实现 C++ 11 所有语言特性的编译器。

Debian 8 Jessie

  • 更改仓库源
1
2
3
4
5
6
# 备份配置文件
# cp /etc/apt/sources.list /etc/apt/sources.list.bak

# 更改仓库源
# echo "deb http://ftp.us.debian.org/debian/ jessie main contrib non-free" >> /etc/apt/sources.list
# echo "deb-src http://ftp.us.debian.org/debian/ jessie main contrib non-free" >> /etc/apt/sources.list
  • 安装 GCC、G++、GDB
1
2
3
4
5
6
# 安装软件(最后得到的版本是4.8.4)
# apt-get install -y gcc-4.8 g++-4.8 gdb

# 建立软链接(可选)
# ln -s /usr/bin/gcc-4.8 /usr/bin/gcc
# ln -s /usr/bin/g++-4.8 /usr/bin/g++

Debian 9 Stretch

提示

  1. build-essential 指的是编译程序必需的软件包,包含了 GCC、G++、Make 等工具
  2. 在 Debian 9 Stretch 上安装 build-essential 后,得到的 GCC、G++ 的版本是 6.3.0
  3. 若希望在 Debian 9 Stretch 上安装低版本的 GCC/G++(例如 4.8),那么可以将上面 Debian 8 Jessie 的仓库源地址添加到 Debian 9 Stretch 系统里,然后使用同样的方法分别单独安装 GCC/G++
  • 更改仓库源
1
2
3
4
5
6
7
8
9
10
11
12
# 备份配置文件
# cp /etc/apt/sources.list /etc/apt/sources.list.bak

# 更改仓库源
# echo "deb http://mirrors.163.com/debian/ stretch main non-free contrib" > /etc/apt/sources.list
# echo "deb http://mirrors.163.com/debian/ stretch-updates main non-free contrib" >> /etc/apt/sources.list
# echo "deb http://mirrors.163.com/debian/ stretch-backports main non-free contrib" >> /etc/apt/sources.list
# echo "deb-src http://mirrors.163.com/debian/ stretch main non-free contrib" >> /etc/apt/sources.list
# echo "deb-src http://mirrors.163.com/debian/ stretch-updates main non-free contrib" >> /etc/apt/sources.list
# echo "deb-src http://mirrors.163.com/debian/ stretch-backports main non-free contrib" >> /etc/apt/sources.list
# echo "deb http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib" >> /etc/apt/sources.list
# echo "deb-src http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib" >> /etc/apt/sources.list
  • 安装 GCC、G++、GDB
1
# apt-get install -y build-essential gdb

参考博客