Installing GCC from source on Alpine

The quickest way to install GCC on Alpine Linux is by issuing the following command:

apk add build-base

source: https://wiki.alpinelinux.org/wiki/GCC


It turns out that in this particular case one needs to install mpc1-dev, gmp-dev or mpfr-dev. I was missing out on mpc1-dev.

sudo apk add mpc1-dev

The best way to install all necessary libraries to compile gcc is using ./contrib/download_prerequisites script in the gcc source directory. That will download the support libraries and create symlinks, causing them to be built automatically as part of the gcc build process.

The steps to compile gcc version 6.4.0 on Alpine linux are:

apk add --no-cache make build-base
wget https://ftp.gnu.org/gnu/gcc/gcc-6.4.0/gcc-6.4.0.tar.gz
tar -xzvf gcc-6.4.0.tar.gz
cd gcc-6.4.0
./contrib/download_prerequisites
cd ..
mkdir objdir
cd objdir
./../gcc-6.4.0/configure --prefix=$HOME/GCC-6.4.0 --disable-multilib
make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc