直接贴代码,有英文注释,
里面很多地方的选项可以根据情况打开
默认会安装在/usr/local/bin下
如果想安装其他版本,只需要改变第5行中的version字段即可。
下载、编译、环境变量设置 一条龙。
-
#! /bin/bash
-
-
# this script make it easy for user to update or install a new version gcc
-
-
GCC_V='4.9.0'
-
INSTALL_DIR=/usr/local
-
-
# install some basic utils
-
sudo yum install -y binutils glibc-static libstdc++-static;
-
-
# wget http://ftp.gnu.org/gnu/gcc/gcc-${GCC_V}/gcc-${GCC_V}.tar.bz2 -O gcc-${GCC_V}.tar.bz2
-
wget http://mirror.bjtu.edu.cn/gnu/gcc/gcc-${GCC_V}/gcc-${GCC_V}.tar.bz2
-
-
#wget http://mirrors.ustc.edu.cn/gnu/gcc/gcc-${GCC_V}/gcc-${GCC_V}.tar.bz2
-
tar jxf gcc-${GCC_V}.tar.bz2
-
cd gcc-${GCC_V}
-
-
# let the gcc download it's need
-
./contrib/download_prerequisites
-
cd ..
-
-
# build in a separate dir
-
mkdir build_gcc${GCC_V}
-
cd build_gcc${GCC_V}
-
-
# these options are refer to the system built-in gcc-4.4.7 options
-
# you can change it as you need
-
../gcc-${GCC_V}/configure --prefix=${INSTALL_DIR} --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++ --disable-dssi --disable-multilib --enable-libgcj-multifile --with-ppl --with-cloog --with-tune=generic
-
-
# this number can change , which N may from 2 ~ 64 ,depend on your core numbers
-
# usually it use N = 2 * Core
-
make -j2
-
sudo make install
-
-
#if you want to install in a different dir
-
# or you want install it to other same platform os, you can use
-
# mkdir /home/xxx/gcc-${GCC_V}-install
-
# make DESTDIR=/home/xxx/gcc-${GCC_V}-install install
-
# tar jcf gcc-${GCC_V}-install.tar.bz2 /home/xxx/gcc-${GCC_V}-install
-
# once you've copied this bz2 to the dest os, you can
-
# tar jxvf gcc-${GCC_V}-install.tar.bz2
-
# cd gcc-${GCC_V}-install
-
# sudo cp -rH usr / # this will copy the bins and libs to the root dir
-
-
-
cd ..
-
-
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${INSTALL_DIR}/lib64:${INSTALL_DIR}/lib" >> ~/.bash_profile
-
echo "export LD_LIBRARY_PATH" >> ~/.bash_profile
-
. ~/.bash_profile
-
-
# if you want to install gcc for all users
-
# you may add LD_LIBRARY_PATH to /etc/ld.so.conf.d/gcc.conf
-
# echo "${INSTALL_DIR}/lib64" >> /etc/ld.so.conf.d/gcc.conf
-
# echo "${INSTALL_DIR}/lib" >> /etc/ld.so.conf.d/gcc.conf
-
-
sudo ldconfig
-
-
#rm -rf build_gcc${GCC_V} gcc-${GCC_V}
#! /bin/bash
# this script make it easy for user to update or install a new version gcc
GCC_V='4.9.0'
INSTALL_DIR=/usr/local
# install some basic utils
sudo yum install -y binutils glibc-static libstdc++-static;
# wget {GCC_V}/gcc-${GCC_V}.tar.bz2 -O gcc-${GCC_V}.tar.bz2
wget {GCC_V}/gcc-${GCC_V}.tar.bz2
#wget {GCC_V}/gcc-${GCC_V}.tar.bz2
tar jxf gcc-${GCC_V}.tar.bz2
cd gcc-${GCC_V}
# let the gcc download it's need
./contrib/download_prerequisites
cd ..
# build in a separate dir
mkdir build_gcc${GCC_V}
cd build_gcc${GCC_V}
# these options are refer to the system built-in gcc-4.4.7 options
# you can change it as you need
../gcc-${GCC_V}/configure --prefix=${INSTALL_DIR} --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++ --disable-dssi --disable-multilib --enable-libgcj-multifile --with-ppl --with-cloog --with-tune=generic
# this number can change , which N may from 2 ~ 64 ,depend on your core numbers
# usually it use N = 2 * Core
make -j2
sudo make install
#if you want to install in a different dir
# or you want install it to other same platform os, you can use
# mkdir /home/xxx/gcc-${GCC_V}-install
# make DESTDIR=/home/xxx/gcc-${GCC_V}-install install
# tar jcf gcc-${GCC_V}-install.tar.bz2 /home/xxx/gcc-${GCC_V}-install
# once you've copied this bz2 to the dest os, you can
# tar jxvf gcc-${GCC_V}-install.tar.bz2
# cd gcc-${GCC_V}-install
# sudo cp -rH usr / # this will copy the bins and libs to the root dir
cd ..
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${INSTALL_DIR}/lib64:${INSTALL_DIR}/lib" >> ~/.bash_profile
echo "export LD_LIBRARY_PATH" >> ~/.bash_profile
. ~/.bash_profile
# if you want to install gcc for all users
# you may add LD_LIBRARY_PATH to /etc/ld.so.conf.d/gcc.conf
# echo "${INSTALL_DIR}/lib64" >> /etc/ld.so.conf.d/gcc.conf
# echo "${INSTALL_DIR}/lib" >> /etc/ld.so.conf.d/gcc.conf
sudo ldconfig
#rm -rf build_gcc${GCC_V} gcc-${GCC_V}