These are some quick instructions on how to build a more recent version of GCC than is provided by the
devel-tools package on the Cent OS based Amazon Linux AMI. (currently GCC 4.8.3) You may, for example, wish to use a more recent version to compile GROMACS – that is my interest. If so, then these instructions assume you have done all the steps up to, but not including, compiling GROMACS in this post. Compiling GCC needs several GB of disk space so if you use the default 8GB for an EC2 AMI it will run out of disk space; increasing this to 12 GB is sufficient.
First let’s find out what versions of GCC are available.
[ec2-user@ip-172-30-0-42 ~]$ svn ls svn://gcc.gnu.org/svn/gcc/tags | grep gcc | grep release ... gcc_4_8_3_release/ gcc_4_8_4_release/ gcc_4_8_5_release/ gcc_4_9_0_release/ gcc_4_9_1_release/ gcc_4_9_2_release/ gcc_4_9_3_release/ gcc_5_1_0_release/ gcc_5_2_0_release/ gcc_5_3_0_release/
As you can see when I wrote this 5.3.0 was the most recent stable version, so let’s try that one. I’m going to compile everything inside a folder called packages/ so let’s create that then use subversion to check out version 5.3.0 (this is going to download a lot of files so will take a minute or two)
[ec2-user@ip-172-30-0-42 ~]$ mkdir ~/packages [ec2-user@ip-172-30-0-42 ~]$ cd ~/packages [ec2-user@ip-172-30-0-42 packages]$ svn co svn://gcc.gnu.org/svn/gcc/tags/gcc_5_3_0_release/ A gcc_5_3_0_release/config-ml.in A gcc_5_3_0_release/libitm ... A gcc_5_3_0_release/fixincludes/fixopts.c A gcc_5_3_0_release/install-sh A gcc_5_3_0_release/ylwrap U gcc_5_3_0_release Checked out revision 232268. [ec2-user@ip-172-30-0-42 packages]$ cd gcc_5_3_0_release/
GCC needs some prerequisites which are installed by this script.
[ec2-user@ip-172-30-0-42 gcc_5_3_0_release]$ ./contrib/download_prerequisites --2016-01-12 13:24:23-- ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2 => ‘mpfr-2.4.2.tar.bz2’ Resolving gcc.gnu.org (gcc.gnu.org)... 22.214.171.124 ... isl-0.14.tar.bz2 100%[=====================>] 1.33M 693KB/s in 2.0s 2016-01-12 13:24:39 (693 KB/s) - ‘isl-0.14.tar.bz2’ saved 
Go up a level, make a build directory and move there.
[ec2-user@ip-172-30-0-42 gcc_5_3_0_release]$ cd .. [ec2-user@ip-172-30-0-42 packages]$ mkdir gcc_5_3_0_release_build/ [ec2-user@ip-172-30-0-42 packages]$ cd gcc_5_3_0_release_build/
Now we are in a position to compile GCC 5.3.0. This took about 50 min using all eight cores of a
c3.2xlarge instance, so this is a good moment to go and have lunch. Note that since the instance I am compiling on has 8 virtual CPUs, I can use the
-j 8 flag to tell make to use up to 8 threads during compilation which will speed things up. If you are using a micro instance, just omit the
-j 8 (but good luck as that would take a long time).
[ec2-user@ip-172-30-0-42 gcc_5_3_0_release_build]$ ../gcc_5_3_0_release/configure && make -j 8 && sudo make install && echo "success" && date checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... x86_64-unknown-linux-gnu checking for a BSD-compatible install... /usr/bin/install -c checking whether ln works... yes ...
Hopefully you now have a newer version of GCC to compile binaries with. With any luck it might even give you a performance boost.