温馨提示×

CentOS GCC环境怎么配置

小樊
39
2025-03-03 08:42:10
栏目: 智能运维
Centos服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在CentOS上配置GCC环境可以通过以下几种方法实现:

使用yum安装GCC

这是最简单的方法,适用于需要快速配置GCC环境的情况。

yum -y install gcc gcc-c++

源码编译安装GCC

如果需要安装特定版本的GCC,可以下载源码进行编译安装。以下是安装GCC 14.2.0的步骤:

  1. 下载源码包
wget https://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-14.2.0/gcc-14.2.0.tar.gz
  1. 解压源码包
tar -zxvf gcc-14.2.0.tar.gz
  1. 安装依赖
cd gcc-14.2.0
./contrib/download_prerequisites
  1. 编译安装
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
  1. 配置环境变量
echo "export PATH=/usr/local/gcc-14.2.0/bin:$PATH" >> /etc/profile
source /etc/profile

使用devtoolset临时启用GCC版本

如果你需要临时启用或切换GCC版本,可以使用devtoolset

scl enable devtoolset-9 bash

这将在当前shell会话中启用GCC 9.3。

永久启用GCC版本

如果希望永久启用某个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环境配置方法

0