Debian 系统安装 C++ 编译器
一 安装方式
安装基础工具链(推荐):一次性安装 gcc、g++、make 等常用构建工具,适合大多数开发场景。
sudo apt update
sudo apt install build-essential
仅安装 g++(最小安装):如果你只需要 C++ 编译器 而不需要完整的构建工具链。
sudo apt update
sudo apt install g++
二 验证安装
gcc --version
g++ --version
g++ (Debian 12.x.x) 12.x.x
三 编译与运行示例
#include <iostream>
int main() {
std::cout << "Hello, Debian C++\n";
return 0;
}
g++ hello.cpp -o hello
./hello
g++ -std=c++17 -Wall -Wextra -O2 -g hello.cpp -o hello
四 安装特定版本与多版本切换(可选)
sudo apt update
sudo apt install gcc-12 g++-12
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 100
sudo update-alternatives --config gcc
sudo update-alternatives --config g++