在CentOS上配置GCC环境可以通过以下几种方法实现:
这是最简单的方法,适用于需要快速配置GCC环境的情况。
yum -y install gcc gcc-c++
如果需要安装特定版本的GCC,可以下载源码进行编译安装。以下是安装GCC 14.2.0的步骤:
wget https://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-14.2.0/gcc-14.2.0.tar.gz
tar -zxvf gcc-14.2.0.tar.gz
cd gcc-14.2.0
./contrib/download_prerequisites
cd ..
mkdir build && cd build
../configure --prefix=/usr/local/gcc-14.2.0 --with-gmp=/usr/local/gmp-6.2.1 --with-mpfr=/usr/local/mpfr-4.1.0 --with-mpc=/usr/local/mpc-1.2.1 --with-isl=/usr/local/isl-0.24 --with-gettext=/usr/local/gettext-0.22 --enable-threads=posix --enable-long-long --enable-languages=c,c++ --disable-checking --disable-multilib
make -j 8
sudo make install
echo "export PATH=/usr/local/gcc-14.2.0/bin:$PATH" >> /etc/profile
source /etc/profile
如果你需要临时启用或切换GCC版本,可以使用devtoolset
。
scl enable devtoolset-9 bash
这将在当前shell会话中启用GCC 9.3。
如果希望永久启用某个GCC版本,可以将以下内容添加到/etc/profile
文件中:
echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile
source /etc/profile
这样,每次打开新的终端时都会自动启用指定的GCC版本。
以上就是在CentOS上配置GCC环境的基本步骤。根据你的需求,可以选择使用yum安装、源码编译或者使用devtoolset
来管理不同版本的GCC环境。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:CentOS GCC环境配置方法