编译工具准备
bash
yum -y install gcc
yum -y install gcc-c++
yum -y install bzip2 zlib-devel
下载gcc源码包
wget http://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/gcc-7.3.0/gcc-7.3.0.tar.gz
解压源码包下载以赖包
bash
tar zxf gcc-7.3.0.tar.gz
cd gcc-7.3.0
./contrib/download_prerequisites
创建安装目录
bash
mkdir /usr/local/gcc-7.3.0
源码编译
bash
mkdir build && cd build
../configure --prefix=/usr/local/gcc-7.3.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib
make -j4 && make install
添加环境变量
bash
# 添加环境变量
echo 'export LD_LIBRARY_PATH=/usr/local/gcc-7.3.0/lib:$LD_LIBRARY_PATH' >> /etc/profile
echo 'export PATH=/usr/local/gcc-7.3.0/bin:$PATH' >> /etc/profile
# 更新profile文件使之立即生效
source /etc/profile