gccをCentOS 5.xにインストール

ビルド用ディレクトリとインストール先ディレクトリを作成

$ cd ~
$ mkdir build
$ cd ~
$ mkdir local
$ cd local
$ mkdir gcc

ソースを取得して展開

$ wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-4.9.3/gcc-4.9.3.tar.gz
$ tar zxvf gcc-4.9.3.tar.gz

ビルドに必要なライブラリを取得

$ cd gcc-4.9.3
$ ./contrib/download_prerequisites

configureとmake、make install

$ cd ~
$ cd build
$ ../gcc-4.9.3/configure --prefix=/home/user/local/gcc --disable-bootstrap --with-system-zlib --disable-multilib --enable-languages=c,c++
$ make
$ make install

参考URL
http://www.mk-mode.com/octopress/2014/09/30/installation-newest-gcc-by-src-on-linux-mint/
https://gcc.gnu.org/ml/gcc-help/2012-07/msg00018.html
http://stackoverflow.com/questions/26808416/gcc-4-9-2-build-error-on-rhel6

node.jsのnpm installでこのgccを使用する例

$ CXX=/home/user/local/gcc/bin/gcc npm install microtime