在CentOS系统中配置GCC编译器通常涉及以下几个步骤:
sudo yum update
sudo yum groupinstall "Development Tools"
gcc --version
如果安装成功,将显示GCC的版本信息。
tar -zxvf gcc-<version>.tar.gz
cd gcc-<version>
mkdir build && cd build
../configure --prefix=/usr/local/gcc-<version> --enable-languages=c,c++ --disable-multilib
make -j$(nproc)
sudo make install
echo "/usr/local/gcc-<version>/bin" >> /etc/profile
source /etc/profile
gcc --version
如果需要升级GCC版本,可以使用CentOS的软件集合(SCL):
sudo yum install centos-release-scls
sudo yum install devtoolset-<version>-gcc*
scl enable devtoolset-<version> bash
编辑 /etc/profile
文件,添加以下行:
source /opt/rh/devtoolset-<version>/enable
然后执行:
source /etc/profile
以上步骤应该可以帮助您在CentOS系统上安装和配置GCC编译器。如果系统预先安装了旧版本的GCC,新安装的版本将与之并存,您可以通过更新PATH环境变量或使用 update-alternatives
命令来切换不同版本的GCC。