動かざることバグの如し

近づきたいよ 君の理想に

CentOS6のgccをアップデートする

2019年2月19日追記

devtoolsetのバージョン上げた

概要

CentOS6ではyum経由でインストールできるgccのバージョンがとても古い。(強調

# gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-17)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

これだとruby2.5のビルドができない!が、Developer Toolsetというのをインストールすると新しめのgccがインストールできるとのこと

環境

インストール

順番にyum installしていく

# yum install centos-release-scl
# yum install scl-utils
# yum install devtoolset-7-gcc devtoolset-7-gcc-c++ devtoolset-7-binutils

↑はインストールするパッケージをビルドによく使うものだけに絞っている。全部くれって場合はyum install devtoolset-7すればおk

あと今回は7をインストールしているが、他のバージョンをインストールすることも可能 各devtoolsetにおけるGCCのバージョンの対応は以下

  • devtoolset-3 4.9.2
  • devtoolset-4 5.3.1
  • devtoolset-6 6.3.1
  • devtoolset-7 7.2.1

有効化

パッケージをインストールするだけではダメで、明示的にこのgccを使います!ってコマンドを叩かなくてはいけない。

# scl enable devtoolset-7 bash

すると新しくなってる

# gcc --version
gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

常にインストールした新しいgccを使ってビルドさせろって場合は/etc/profile.d/に適当なスクリプトを作ると吉

$ cat /etc/profile.d/enabledevtoolset-7.sh
#!/bin/bash
source scl_source enable devtoolset-7