下面给你一套适合新手的 CentOS 配置 C++ 开发环境的步骤,从零开始,照着做就行。
cat /etc/redhat-release
常见如:CentOS Linux release 7.x 或 CentOS Stream 8/9
sudo yum update -y
(CentOS 8+ 用 dnf 也可以)
sudo yum groupinstall "Development Tools" -y
这会自动安装:
gccg++makeg++ --version
gcc --version
能看到版本号就说明 OK 了。
mkdir ~/cpp_demo
cd ~/cpp_demo
vim hello.cpp
(不会 vim 可用 nano hello.cpp)
#include <iostream>
using namespace std;
int main() {
cout << "Hello CentOS C++" << endl;
return 0;
}
g++ hello.cpp -o hello
./hello
输出:
Hello CentOS C++
✅ 成功!
g++ hello.cpp -o hello -std=c++11 -Wall
-std=c++11:使用 C++11 标准-Wall:显示警告(推荐)sudo yum install code -y # CentOS 8+
或装 vim + 插件也行
sudo yum install epel-release -y
sudo yum install cmake -y
如果你愿意,我可以:
你现在是 CentOS 几?主要用来学还是干活?