6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AmazonLinuxにGCC5.xをインストールする

Last updated at Posted at 2017-08-27

AmazonLinuxではyumでGCCをインストールすると、
バージョン4.8.5がインストールされるのですが、
バージョン5.xが必要だったので手動ビルドをしました。
時間がかかりましたが無事インストールできたましたので、その方法を記載します。

環境

  • AMI:Amazon Linux AMI 2017.03.1
  • インスタンスタイプ:t2.micro
  • ストレージ:20GB
  • GCCバージョン:5.4.0

手順

1.t2.microなので先にSWAPを500MB作成

$ SWAP=/tmp/swap
$ dd if=/dev/zero of=$SWAP bs=1M count=500
$ mkswap $SWAP
$ sudo swapon $SWAP

2.GCCインストールに必要なツール類をインストール

$ sudo yum install gmp-devel mpfr-devel libmpc-devel

3.gccのソースをダウンロード

$ wget ftp://ftp.gnu.org/gnu/gcc/gcc-5.4.0/gcc-5.4.0.tar.bz2

4.ダウンロードしたソースを解凍

$ tar xvjf gcc-5.4.0.tar.bz2

5.解凍後のディレクトリへ移動

$ cd gcc-5.4.0

6.ビルドディレクトリ作成

$ mkdir build

7.ビルドディレクトリへ移動

$ cd build

8.Makefileを生成

$ ../configure --prefix=${HOME}/local/gcc-5.4.0 --disable-multilib

9.ビルド実行

$ make

次のエラーが発生

checking for uintmax_t... yes
checking for uintptr_t... yes
checking for int64_t underlying type... long long
configure: error: error verifying int64_t uses long long
make[2]: *** [configure-stage1-gcc] Error 1
make[2]: Leaving directory `/home/ec2-user/gcc-5.4.0/build'
make[1]: *** [stage1-bubble] Error 2
make[1]: Leaving directory `/home/ec2-user/gcc-5.4.0/build'
make: *** [all] Error 2

g++コンパイラがないから起きたらしい

10.g++コンパイラをインストール

$ sudo yum install gcc-c++

11.再度ビルドを実行

$ nohup make > make.log &

ビルドを試したとき数時間経っても終わらなかったため、
nohupでの実行に切り替えました。
専用のログファイルに記録して監視をしました。

21時間! かかって無事終わりました。
ディスク占有は8.8GBとなっていましたので、
t2.microでそのままデフォルトのストレージ容量では厳しそうです。

12.インストールを実行

$ make install

13.homeに戻る

$ cd

14..bash_profileに環境変数追加

$ vi .bash_profile

以下を最後の行に追加

export PATH=$HOME/local/gcc-5.4.0/bin:$PATH
export LD_LIBRARY_PATH=$HOME/local/gcc-5.4.0/lib64/:$LD_LIBRARY_PATH

15.変更を適用

$ source .bash_profile

16.バージョンを確認

$ gcc --version
gcc (GCC) 5.4.0

無事バージョン5.4.0がインストールできました。
機能豊富なツールなので仕方ないとも思いますが、21時間は長いですね。。。

こちらの記事を参考にさせていただきました。

awsでAmazon Linux AMIに最新のGCCを入れる
http://tech.ckme.co.jp/gcc.shtml

Bug 63509 - Misleading error message when building gcc without C++ compiler installed
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63509


9/1追記

再度インストール機会があって以下をしたところ、ビルド時間が 2時間 に短縮されました。
必ず短縮できるとは限りませんが参考までに共有します。

  • SWAPを1GBに設定
  • /homeをEBSで別ボリュームに指定
6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?