在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。