LAMP 2020LinuxOpen Source

Development Tools – Building a LAMP Server (2020)

Here we will cover setting up development tools for use in compiling software. While most distributions come with a set of development tools you can install from their repository, there are some that we may wish to compile manually, usually because the distribution contains very old versions.

Important: you can probably skip most of this article since the tested distributions tend to have recent enough packages. But at the minimum, do the Essentials section. The GCC section is what will take the most time, which is why I have placed it last.

Estimated time (this post only): 5 minutes to 10+ hours
* varies depending on whether you choose to compile everything listed from source and how many processor cores you have

Essentials

There are a few essential tools you may need to download from the repository first. You may have some of these installed, but let’s check anyway.

CentOSFedoraUbuntuDebianopenSUSEArch Linux

Do the following.

sudo sed -i 's/enabled=0/enabled=1/' \
/etc/yum.repos.d/CentOS-PowerTools.repo
sudo dnf install epel-release
sudo dnf install -y \
https://packages.groonga.org/centos/8/groonga-release-latest.noarch.rpm
sudo dnf groupinstall "Development Tools"

sudo dnf install aspell autoconf autogen automake binutils-devel bison \
bison-devel boost-devel bzip2 bzip2-devel cmake cracklib-devel cvs \
cyrus-sasl-scram dejagnu dkms doxygen dpkg expat-devel fakeroot flex \
freetds freetds-devel freetype-devel gcc-c++ gdb gnulib gnutls-devel \
gperf groonga-devel java-devel jemalloc-devel kernel-devel-$(uname -r) \
krb5-devel libaio-devel libarchive-devel libcurl-devel libdbi-dbd-mysql \
libedit-devel libevent-devel libjpeg-turbo-devel libmcrypt-devel \
libmpc-devel libsphinxclient libsphinxclient-devel libstdc++-devel \
libstemmer-devel libtidy-devel libtirpc-devel libxml2-devel libXpm-devel \
libxslt-devel libzstd-devel lynx lz4-devel lzo-devel make mecab-devel \
mercurial msgpack-devel multilib-rpm-config nano ncurses-devel \
openldap-devel openssl-devel pam-devel patchelf pcre-devel perl \
python2-devel python3-devel qt5-qtbase-devel re2c readline-devel rpcgen \
selinux-policy-devel snappy-devel sphinx svn systemd-devel \
systemtap-sdt-devel tar texlive thrift-devel unixODBC-devel uuid-devel \
uw-imap-utils valgrind wget xinetd zeromq-devel

sudo alternatives --set python /usr/bin/python3
sudo dnf groupinstall "Development Tools"

sudo dnf install aspell autoconf autogen automake binutils-devel bison \
bison-devel boost-devel bzip2 bzip2-devel cmake cracklib-devel cvs \
cyrus-sasl-scram dejagnu dkms doxygen dpkg expat-devel fakeroot flex \
freetds freetds-devel freetype-devel gcc-c++ gdb gnulib gnutls-devel \
gperf gprbuild groonga-devel java-devel jemalloc-devel Judy-devel \
kernel-devel-$(uname -r) krb5-devel libaio-devel libarchive-devel \
libcurl-devel libdbi-dbd-mysql libedit-devel libevent-devel \
libjpeg-turbo-devel libmcrypt-devel libmpc-devel libsphinxclient \
libsphinxclient-devel libstdc++-devel libstemmer-devel libtidy-devel \
libtirpc-devel libxml2-devel libXpm-devel libxslt-devel libzstd-devel \
lynx lz4-devel lzo-devel make mecab-devel mercurial msgpack-devel \
multilib-rpm-config nano ncurses-devel openldap-devel openssl-devel \
pam-devel patchelf pcre-devel perl perl-generators python2-devel \
python3-devel qt5-qtbase-devel re2c readline-devel rpcgen \
selinux-policy-devel snappy-devel sphinx svn systemd-devel \
systemtap-sdt-devel tar texlive thrift-devel unixODBC-devel uuid-devel \
uw-imap-utils valgrind wget xinetd zeromq-devel
sudo apt-get -y install software-properties-common
sudo add-apt-repository -y universe
sudo add-apt-repository -y ppa:groonga/ppa
sudo sed -i '/deb-src/s/^# //' /etc/apt/sources.list
sudo apt update
sudo apt install build-essential

sudo apt install aspell autoconf autogen automake autopoint \
autotools-dev binutils-dev bison bzip2 bzr checkpolicy chrpath cmake \
cmake-data comerr-dev cracklib-runtime ctags cvs debhelper \
default-jdk-headless dejagnu dh-apparmor dh-autoreconf dh-exec \
dh-strip-nondeterminism dkms doxygen dwz equivs expect flex freetds-bin \
freetds-dev gcc gdb gettext git glibc-source gnat gnat-gps gnulib \
gnutls-dev gperf gprbuild graphviz guile-3.0 icu-devtools \
intltool-debian krb5-multidev libaio-dev libarchive-dev \
libarchive-zip-perl libbabeltrace1 libboost-all-dev libbz2-dev libcrack2 \
libcrack2-dev libcroco3 libcurl4-openssl-dev libdbd-mysql-perl \
libdebhelper-perl libdbi-perl libdw1 libedit-dev libevent-dev libexpat-dev \
libfile-stripnondeterminism-perl libfreetype-dev libgmp-dev \
libgmpxx4ldbl libgnutls-dane0 libgnutls-openssl27 libgnutls28-dev \
libgnutlsxx28 libgroonga-dev libgssrpc4 libicu-dev libidn2-dev \
libjemalloc-dev libjemalloc2 libjsoncpp1 libjudy-dev libjudydebian1 \
libkadm5clnt-mit11 libkadm5srv-mit11 libkdb5-9 libkrb5-dev libldap2-dev \
libltdl-dev liblz4-dev liblzma-dev liblzo2-dev libmcrypt-dev libmcrypt4 \
libmecab-dev libmsgpack-dev libncurses-dev libncurses5-dev libodbc1 \
libp11-kit-dev libpam0g-dev libpcre16-3 libpcre3-dev libpcre32-3 \
libpcrecpp0v5 libreadline-dev librhash0 libsasl2-dev libstdc++-10-dev \
libstemmer-dev libsnappy-dev libsnappy1v5 libsub-override-perl \
libsystemd-dev libthrift-dev libtidy-dev libtirpc-dev libtasn1-6-dev \
libtool libturbojpeg libturbojpeg-dev libunbound8 libxml2-dev \
libxml2-utils libxpm-dev libxslt-dev libzmq5-dev libzstd-dev \
linux-headers-$(uname -r) lynx make mercurial nano nettle-dev odbcinst \
odbcinst1debian2 openjdk-8-jdk-headless patchelf po-debconf re2c ruby \
python2-dev python3-pip semodule-utils sasl2-bin \
software-properties-common subversion systemtap-sdt-dev tar texlive \
unixodbc-dev uuid-dev uw-mailutils valgrind wget xinetd zlib1g-dev
sudo apt update
sudo apt install -V wget
wget https://packages.groonga.org/debian/groonga-apt-source-latest-buster.deb
sudo apt install -V ./groonga-apt-source-latest-buster.deb
sudo sed -i '/deb-src/s/^# //' /etc/apt/sources.list
sudo apt update
sudo apt install build-essential

sudo apt install aspell autoconf autogen automake autopoint \
autotools-dev binutils-dev bison bzip2 bzr checkpolicy chrpath cmake \
cmake-data comerr-dev cracklib-runtime ctags cvs debhelper \
default-jdk-headless dejagnu dh-apparmor dh-autoreconf dh-exec \
dh-strip-nondeterminism dkms doxygen dwz equivs expect flex freetds-bin \
freetds-dev gcc gdb gettext git glibc-source gnat gnat-gps gnulib \
gnutls-dev gperf gprbuild graphviz guile-2.0 icu-devtools \
intltool-debian krb5-multidev libaio-dev libarchive-dev \
libarchive-zip-perl libbabeltrace1 libboost-all-dev libbz2-dev libcrack2 \
libcrack2-dev libcroco3 libcurl4-openssl-dev libdbd-mysql-perl \
libdbi-perl libdw1 libedit-dev libevent-dev libexpat-dev \
libfile-stripnondeterminism-perl libfreetype6-dev libgmp-dev \
libgmpxx4ldbl libgnutls-dane0 libgnutls-openssl27 libgnutls28-dev \
libgnutlsxx28 libgroonga-dev libgssrpc4 libicu-dev libidn2-dev \
libjemalloc-dev libjemalloc2 libjsoncpp1 libjudy-dev libjudydebian1 \
libkadm5clnt-mit11 libkadm5srv-mit11 libkdb5-9 libkrb5-dev libldap2-dev \
libltdl-dev liblz4-dev liblzma-dev liblzo2-dev libmcrypt-dev libmcrypt4 \
libmecab-dev libmsgpack-dev libncurses-dev libncurses5-dev libodbc1 \
libp11-kit-dev libpam0g-dev libpcre16-3 libpcre3-dev libpcre32-3 \
libpcrecpp0v5 libreadline-dev librhash0 libsasl2-dev libstdc++-8-dev \
libstemmer-dev libsnappy-dev libsnappy1v5 libsub-override-perl \
libsystemd-dev libthrift-dev libtidy-dev libtirpc-dev libtasn1-6-dev \
libtool libturbojpeg0 libturbojpeg0-dev libunbound8 libxml2-dev \
libxml2-utils libxpm-dev libxslt-dev libzmq5-dev libzstd-dev \
linux-headers-$(uname -r) lynx make mercurial nano nettle-dev odbcinst \
odbcinst1debian2 openjdk-11-jdk-headless patchelf po-debconf re2c ruby \
python2-dev python3-pip semodule-utils sasl2-bin \
software-properties-common subversion systemtap-sdt-dev tar texlive \
unixodbc-dev uuid-dev uw-mailutils valgrind wget xinetd zlib1g-dev
sudo zypper refresh
sudo zypper update
sudo zypper install -t pattern devel_C_C++

sudo zypper install aspell aspell-devel autogen boost-devel bzip2 \
bzr cglib checkpolicy cmake cmake-full cmake-man cpprest-devel \
cracklib-devel cyrus-sasl-scram dejagnu dkms doxygen dpkg fakeroot \
freetds-devel freetype-devel gdb gmpc-devel graphviz guile \
java-11-openj9-devel jemalloc-devel judy-devel \
kernel-default-devel=$(uname -r | sed 's/-default.*//g') \
keyutils-devel krb5-devel libaio-devel libarchive-devel libbz2-devel \
libcurl-devel libdbi-drivers-dbd-mysql libedit-devel libevent-devel \
libexpat-devel libgnutls-devel libicu-devel libjpeg-turbo libjpeg8-devel \
libjsoncpp19 liblz4-devel libnuma-devel libopenssl-1_1-devel \
libopenssl-devel libpcre16-0 libpcrecpp0 libpcreposix0 libpng16-devel \
libpq5 libqt5-qtbase-devel librhash0 libselinux-devel \
libsphinxclient-0_0_1 libsphinxclient-devel libthrift-devel libtidy-devel \
libtirpc-devel libverto-devel libxml2-devel libXpm-devel libxslt-devel \
libzstd-devel lynx lzo-devel make mercurial msgpack-devel nano patchelf \
pcre-devel python3-devel re2c readline-devel rpcgen snappy-devel sphinx \
sqlite3 systemd-devel systemd-rpm-macros systemtap-sdt-devel tar \
tcpd-devel texinfo texlive unixODBC unixODBC-devel uuid-devel \
valgrind-devel wget xinetd xz-devel zeromq-devel

You may need the multilib repo depending on what you install, so do:

sudo nano /etc/pacman.conf

… and un-comment the multilib section. Then do:

sudo pacman -Syyu
sudo reboot

sudo pacman -S base-devel

sudo pacman -S apparmor aspell autoconf autogen automake babeltrace \
bison boost bzip2 bzr chrpath cmake cpio cracklib ctags curl cvs \
cyrus-sasl dejagnu dkms doxygen dpkg expat fakeroot freetds gdb gettext \
git gmp gnutls gperf graphviz guile haskell-uuid icu inetutils intltool \
jdk-openjdk jemalloc jre-openjdk-headless jsoncpp judy keyutils krb5 \
libaio libarchive libcroco libcrossguid libedit libevent libidn \
libjpeg-turbo libmcrypt libp11-kit libpng libstdc++5 libstemmer libtasn1 \
libtirpc libtool libxpm libxslt libxml2 \
linux-headers=$(uname -r | sed 's/-ARCH.*//g' | sed 's/-arch/.arch/g') \
lynx lz4 lzo m4 make mercurial msgpack-c nano ncurses nettle numactl \
openssl pam patchelf pcre python python-pip python2 python2-pip re2c \
readline rhash rpcsvc-proto ruby snappy sqlite strip-nondeterminism svn \
systemd tar texinfo thrift tidy unbound unixodbc valgrind wget xmlto xz \
zeromq zlib zstd judy systemtap

I’ve placed Judy and SystemTap last for this distribution, because they are not always available via pacman. If this is the case, remove them from the above command and install them as follows.

For Judy, do:

cd ~
git clone https://aur.archlinux.org/judy.git
cd judy
makepkg -Acs
sudo pacman -U *.pkg.tar.xz
sudo mv *.pkg.tar.xz /usr/local/src/
cd ~
rm -rf judy

For SystemTap, see the latest release, then do (adjusting version as needed):

TMPVER="4.3"
cd ~
wget -c -t 10 \
https://sourceware.org/systemtap/ftp/releases/systemtap-${TMPVER}.tar.gz
tar zxvf systemtap-${TMPVER}.tar.gz
mkdir -v systemtap-${TMPVER}/bld
cd systemtap-${TMPVER}/bld
../configure --prefix=/usr/local
make
sudo -E env "PATH=$PATH" make install
cd ~
rm systemtap-${TMPVER}.tar.gz
sudo mv systemtap-${TMPVER} /usr/local/src/

Since we are going to be downloading several archives from gnu.org we should verify their signatures. So download their GPG keyring and import it.

cd ~
wget -c -t 10 http://ftp.gnu.org/gnu/gnu-keyring.gpg
gpg --import gnu-keyring.gpg
rm gnu-keyring.gpg

Lastly, since these tools will be installed to /usr/local, you should ensure the lib directory in there will be in your library path (many distributions do this automatically now, but it doesn’t hurt to make sure):

printf "/usr/local/lib\n/usr/local/lib64" | \
sudo tee /etc/ld.so.conf.d/usr-local.conf
sudo ldconfig

You should probably reboot at this point.

sudo reboot

Note On secure_path

Many distributions have the secure_path option set for sudo. This means your path variable will have no effect when running sudo, so the tools you compile will not be used by sudo commands. Normally, you could overcome this problem by adding the -E switch, but in many distributions the -E switch will not override secure_path. There are several ways to overcome this problem.

  1. Set the path environment every time you need it for sudo. Example: sudo -E env "PATH=$PATH" make. This is what most people recommend, but the downside is you have to try to remember when it is or isn’t necessary to set the path when running sudo. This is the only method that is guaranteed to work on all distros, so it is what I will focus on.
  2. Disable secure_path via visudo. This is not recommended for security reasons. It could break sudo.
  3. Edit the secure_path via visudo for every package you compile. This could also break sudo.

Make

Make sure you have the latest version of GNU Make installed. Some distributions ship with a different flavor (not GNU) of Make or an older version. To check:

make -v

The bare minimum you need for this tutorial is GNU Make 3.75, but you can check for the latest version via a GNU Make FTP mirror. There may be advantages to installing the latest version of GNU Make even if your distribution ships with a fairly recent version. So if your distribution has an older version do the following (change version number on first line as needed and copy/paste the rest into your SSH terminal).

TMPVER="4.3"
cd ~
wget -c -t 10 ftpmirror.gnu.org/make/make-${TMPVER}.tar.gz
wget -c -t 10 ftpmirror.gnu.org/make/make-${TMPVER}.tar.gz.sig
gpg --verify make-${TMPVER}.tar.gz.sig make-${TMPVER}.tar.gz

If you see "Good signature" in the results, then the file should be unaltered and you can continue. If you don’t, download again. Now configure and compile.

tar zxvf make-${TMPVER}.tar.gz
mkdir -v make-${TMPVER}/bld
cd make-${TMPVER}/bld
../configure prefix=/usr/local
make && make check

Assuming most of the tests passed, you are ready to install. A couple tests may fail due to timeouts depending on distribution and hardware.

Now install Gnu Make:

sudo make install
cd ~
sudo mv make-${TMPVER} /usr/local/src/
rm make-*
hash -r
make -v
sudo env "PATH=$PATH" make -v

The last two commands will verify that you are using the correct version, both as yourself and when running commands via sudo.


CMake

You will want a fairly new version of CMake, which some distributions do not have in their official repositories. First, check your current version.

cmake --version

Find the latest release version on the CMake download page. If your version is outdated, do the following (change version number on first line as needed and copy/paste the rest into your SSH terminal).

TMPVER="3.18.4"
cd ~
wget -c -t 10 cmake.org/files/v$(echo $TMPVER | \
sed -e 's/\.[^\.]*$//')/cmake-${TMPVER}.tar.gz
wget -c -t 10 cmake.org/files/v$(echo $TMPVER | \
sed -e 's/\.[^\.]*$//')/cmake-${TMPVER}-SHA-256.txt
diff <(sha256sum cmake-${TMPVER}.tar.gz | \
sed 's/ .*//') <(cat cmake-${TMPVER}-SHA-256.txt | \
sed -n '/cmake-'${TMPVER}'.tar.gz/p' | \
sed 's/\(.*\)cmake-'${TMPVER}'.tar.gz$/\1/')

That last command will ensure the checksum is valid. If the two values are not identical, download it again. Otherwise continue:

tar zxvf cmake-${TMPVER}.tar.gz
mkdir -v cmake-${TMPVER}/bld
cd cmake-${TMPVER}/bld
../configure --prefix=/usr/local
make && make test

Assuming all tests passed, you are ready to install.

sudo -E env "PATH=$PATH" make install
cd ~
sudo mv cmake-${TMPVER} /usr/local/src/
rm cmake-*
hash -r
cmake --version
sudo env "PATH=$PATH" cmake --version

The last two commands will verify that you are using the correct version, both as yourself and when running commands via sudo.


Perl

I recommend installing the latest version of Perl. Find the latest non-development version number on the CPAN website. Then check your installed version with the following:

perl -v

If you aren’t running a recent version, you can build it from source with the following commands (change version number on first line as needed and copy/paste the rest into your SSH terminal):

TMPVER="5.32.0"
cd ~
wget -c -t 10 www.cpan.org/src/$(echo $TMPVER | \
sed 's/\..*$//').0/perl-${TMPVER}.tar.gz
wget -c -t 10 www.cpan.org/src/$(echo $TMPVER | \
sed 's/\..*$//').0/perl-${TMPVER}.tar.gz.sha256.txt
diff <(sha256sum perl-${TMPVER}.tar.gz | sed 's/ .*//') \
<(cat perl-${TMPVER}.tar.gz.sha256.txt)

That last command will check the sha256 checksum of the archive against the contents of the text file to ensure the download is valid. You may see a message about there being no newline, but ignore that. So long as both values are identical, the file is good. If the download checks out, continue to compile Perl.

tar xzvf perl-${TMPVER}.tar.gz
cd perl-${TMPVER}
./Configure -des -Dprefix=/usr/local
make && make test

Assuming all tests passed, you can continue installing.

sudo -E env "PATH=$PATH" make install
cd ~
rm perl-*.tar*
sudo mv perl-${TMPVER} /usr/local/src/
hash -r
perl -v
sudo env "PATH=$PATH" perl -v

The last two commands will verify that you are using the correct version, both as yourself and when running commands via sudo.


GCC

Warning: this can be very time-consuming (as much as 10 hours in some cases). Please read these notes carefully to decide if you want to install a different version of GCC.

In short: you can generally just stick with the system-provided GCC for everything (unless otherwise stated), but there may be advantages to upgrading to the latest version. And in rare cases you may need to install an older version for compatibility.

Check your installed version:

gcc -v

Check the GCC Releases page to see the latest releases in each branch.

Using the method I cover here, you could always revert to your old version by pointing to a specific compiler. This process may vary slightly depending on what you are installing (example: ../configure CC=/usr/bin/cc).

THIS IS VERY IMPORTANT!!! If your system is running GCC 7+, some older versions of MariaDB may not compile. This has been reported on Debian, but I encountered the same error on some other distributions. So you may want to install GCC 6 as a backup.

Now, after reading all the warnings, if you want/need to install a different version of GCC, continue.

First of all, note that if you are installing an older version of GCC for compatibility, it is best to install to /opt rather than /usr/local. I chose to install the following versions for each distribution:

CentOSFedoraUbuntu/Debian/openSUSE/Arch Linux

Kept system-provided version. But you should be able safely install GCC 10 to /usr/local (if desired) by following instructions below.

Kept system-provided version since it was already the most recent and I had no trouble compiling anything in this guide with it.

Kept system-provided version, though in some cases you may need to install GCC 6 as a backup to /opt/gcc6 for compiling older versions of MySQL/MariaDB.

Here are the instructions for installing the current latest release in every branch from 6-10. Replace the version in the first line with whatever version you wish to install, replace the path in the second line with the location you wish to install to (read notes above), then copy/paste the rest into your SSH terminal.

GCC 6GCC 7GCC 8GCC 9GCC 10
TMPVER="6.5.0" && TMPPATH="/opt/gcc6"
cd ~
wget -c -t 10 ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
wget -c -t 10 ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
wget -c -t 10 ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
wget -c -t 10 ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2
tar xvjf gmp-6.1.0.tar.bz2
tar xvjf mpfr-3.1.4.tar.bz2
tar zxvf mpc-1.0.3.tar.gz
tar xvjf isl-0.16.1.tar.bz2
wget -c -t 10 ftpmirror.gnu.org/gcc/gcc-${TMPVER}/gcc-${TMPVER}.tar.gz
wget -c -t 10 ftpmirror.gnu.org/gcc/gcc-${TMPVER}/gcc-${TMPVER}.tar.gz.sig
gpg --verify gcc-${TMPVER}.tar.gz.sig gcc-${TMPVER}.tar.gz

If you see "Good signature" in the results, then the file should be unaltered and you can continue. If you don’t, download again. Now create your source tree as recommended by the GCC team.

mkdir -vp gcc-${TMPVER}/bld
tar zxvf gcc-${TMPVER}.tar.gz -C gcc-${TMPVER}
mv gcc-${TMPVER}/gcc-${TMPVER} gcc-${TMPVER}/src
mv gmp-6.1.0 gcc-${TMPVER}/src/gmp
mv mpfr-3.1.4 gcc-${TMPVER}/src/mpfr
mv mpc-1.0.3 gcc-${TMPVER}/src/mpc
mv isl-0.16.1 gcc-${TMPVER}/src/isl
cd gcc-${TMPVER}/bld
TMPVER="7.5.0" && TMPPATH="/usr/local"
cd ~
wget -c -t 10 ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
wget -c -t 10 ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
wget -c -t 10 ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
wget -c -t 10 ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2
tar xvjf gmp-6.1.0.tar.bz2
tar xvjf mpfr-3.1.4.tar.bz2
tar zxvf mpc-1.0.3.tar.gz
tar xvjf isl-0.18.tar.bz2
wget -c -t 10 ftpmirror.gnu.org/gcc/gcc-${TMPVER}/gcc-${TMPVER}.tar.gz
wget -c -t 10 ftpmirror.gnu.org/gcc/gcc-${TMPVER}/gcc-${TMPVER}.tar.gz.sig
gpg --verify gcc-${TMPVER}.tar.gz.sig gcc-${TMPVER}.tar.gz

If you see "Good signature" in the results, then the file should be unaltered and you can continue. If you don’t, download again. Now create your source tree as recommended by the GCC team.

mkdir -vp gcc-${TMPVER}/bld
tar zxvf gcc-${TMPVER}.tar.gz -C gcc-${TMPVER}
mv gcc-${TMPVER}/gcc-${TMPVER} gcc-${TMPVER}/src
mv gmp-6.1.0 gcc-${TMPVER}/src/gmp
mv mpfr-3.1.4 gcc-${TMPVER}/src/mpfr
mv mpc-1.0.3 gcc-${TMPVER}/src/mpc
mv isl-0.18 gcc-${TMPVER}/src/isl
cd gcc-${TMPVER}/bld
TMPVER="8.4.0" && TMPPATH="/usr/local"
cd ~
wget -c -t 10 ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
wget -c -t 10 ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
wget -c -t 10 ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
wget -c -t 10 ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2
tar xvjf gmp-6.1.0.tar.bz2
tar xvjf mpfr-3.1.4.tar.bz2
tar zxvf mpc-1.0.3.tar.gz
tar xvjf isl-0.18.tar.bz2
wget -c -t 10 ftpmirror.gnu.org/gcc/gcc-${TMPVER}/gcc-${TMPVER}.tar.gz
wget -c -t 10 ftpmirror.gnu.org/gcc/gcc-${TMPVER}/gcc-${TMPVER}.tar.gz.sig
gpg --verify gcc-${TMPVER}.tar.gz.sig gcc-${TMPVER}.tar.gz

If you see "Good signature" in the results, then the file should be unaltered and you can continue. If you don’t, download again. Now create your source tree as recommended by the GCC team.

mkdir -vp gcc-${TMPVER}/bld
tar zxvf gcc-${TMPVER}.tar.gz -C gcc-${TMPVER}
mv gcc-${TMPVER}/gcc-${TMPVER} gcc-${TMPVER}/src
mv gmp-6.1.0 gcc-${TMPVER}/src/gmp
mv mpfr-3.1.4 gcc-${TMPVER}/src/mpfr
mv mpc-1.0.3 gcc-${TMPVER}/src/mpc
mv isl-0.18 gcc-${TMPVER}/src/isl
cd gcc-${TMPVER}/bld
TMPVER="9.3.0" && TMPPATH="/usr/local"
cd ~
wget -c -t 10 ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
wget -c -t 10 ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
wget -c -t 10 ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
wget -c -t 10 ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2
tar xvjf gmp-6.1.0.tar.bz2
tar xvjf mpfr-3.1.4.tar.bz2
tar zxvf mpc-1.0.3.tar.gz
tar xvjf isl-0.18.tar.bz2
wget -c -t 10 ftpmirror.gnu.org/gcc/gcc-${TMPVER}/gcc-${TMPVER}.tar.gz
wget -c -t 10 ftpmirror.gnu.org/gcc/gcc-${TMPVER}/gcc-${TMPVER}.tar.gz.sig
gpg --verify gcc-${TMPVER}.tar.gz.sig gcc-${TMPVER}.tar.gz

If you see "Good signature" in the results, then the file should be unaltered and you can continue. If you don’t, download again. Now create your source tree as recommended by the GCC team.

mkdir -vp gcc-${TMPVER}/bld
tar zxvf gcc-${TMPVER}.tar.gz -C gcc-${TMPVER}
mv gcc-${TMPVER}/gcc-${TMPVER} gcc-${TMPVER}/src
mv gmp-6.1.0 gcc-${TMPVER}/src/gmp
mv mpfr-3.1.4 gcc-${TMPVER}/src/mpfr
mv mpc-1.0.3 gcc-${TMPVER}/src/mpc
mv isl-0.18 gcc-${TMPVER}/src/isl
cd gcc-${TMPVER}/bld
TMPVER="10.2.0" && TMPPATH="/usr/local"
cd ~
wget -c -t 10 ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
wget -c -t 10 ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
wget -c -t 10 ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
wget -c -t 10 ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2
tar xvjf gmp-6.1.0.tar.bz2
tar xvjf mpfr-3.1.4.tar.bz2
tar zxvf mpc-1.0.3.tar.gz
tar xvjf isl-0.18.tar.bz2
wget -c -t 10 ftpmirror.gnu.org/gcc/gcc-${TMPVER}/gcc-${TMPVER}.tar.gz
wget -c -t 10 ftpmirror.gnu.org/gcc/gcc-${TMPVER}/gcc-${TMPVER}.tar.gz.sig
gpg --verify gcc-${TMPVER}.tar.gz.sig gcc-${TMPVER}.tar.gz

If you see "Good signature" in the results, then the file should be unaltered and you can continue. If you don’t, download again. Now create your source tree as recommended by the GCC team.

mkdir -vp gcc-${TMPVER}/bld
tar zxvf gcc-${TMPVER}.tar.gz -C gcc-${TMPVER}
mv gcc-${TMPVER}/gcc-${TMPVER} gcc-${TMPVER}/src
mv gmp-6.1.0 gcc-${TMPVER}/src/gmp
mv mpfr-3.1.4 gcc-${TMPVER}/src/mpfr
mv mpc-1.0.3 gcc-${TMPVER}/src/mpc
mv isl-0.18 gcc-${TMPVER}/src/isl

Following is the configuration procedure I used.

If you have trouble running configure for Ada, you can run rm -rf * and re-run configure without it. It isn’t necessary for anything in this guide. I am just including all languages in case you want to compile something else on this machine in the future.

cd ~/gcc-${TMPVER}/bld
../src/configure -v --prefix=${TMPPATH} \
--disable-multilib \
--enable-languages=c,c++,fortran,go,objc,obj-c++,lto,ada

Compile and check. The check process may appear to hang at certain points. You may run into a lot of timeouts during testing for GCC 6, so if time is of the essence and you are just installing GCC 6 for the rare case where you need it, you may want to skip the && make -k check portion of the commands below.

SED=sed
make -j$(nproc) && ulimit -s 32768 && make -k check
../src/contrib/test_summary | grep -A7 Summ

Look over the summary of all tests. If you just want a summary of the unexpected failures, try this:

../src/contrib/test_summary | grep -B4 -A4 unexpected

If you see a lot of unexpected failures, then something may have gone wrong (some unexpected failures are normal depending on your platform and configure options). You can run the last command again (everything before the pipe) to find the details, then look up the errors if you’re concerned. If you have hundreds or thousands of unexpected failures, you’re probably missing some prerequisite. Otherwise you can usually ignore it even if there are a few dozen errors (especially on a slow system or virtual machine, this is normal).

Now, finally, install:

sudo -E env "PATH=$PATH" make install
sudo ldconfig
hash -r
gcc -v
sudo env "PATH=$PATH" gcc -v
${TMPPATH}/bin/gcc -v
sudo env "PATH=$PATH" ${TMPPATH}/bin/gcc -v

The last four commands will verify that you are using the correct version, both as yourself and when running commands via sudo. If you did not install to /usr/local then the first two will show your system-provided version and the last two will show the version you just installed. If you installed to /usr/local then all four should show this new version.

Create some symlinks next (ignore errors; I’m covering various distributions).

GCC 6GCC 7GCC 8GCC 9 & 10
sudo ln -sv ../bin/cpp ${TMPPATH}/lib
sudo ln -sv gcc ${TMPPATH}/bin/cc
sudo install -v -dm755 ${TMPPATH}/lib/bfd-plugins
sudo ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/${TMPVER}/liblto_plugin.so \
${TMPPATH}/lib/bfd-plugins/

Note that the following version numbers may change with future versions of GCC. This is correct as of this writing. You can check by running ls ${TMPPATH}/lib64/libstdc++* or ls ${TMPPATH}/lib/libstdc++*.

sudo ln -sfv ${TMPPATH}/lib64/libstdc++.so.6.0.22-gdb.py \
/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.22-gdb.py
sudo ln -sfv ${TMPPATH}/lib64/libstdc++.so.6.0.22-gdb.py \
/usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.22-gdb.py
sudo ln -sv ../bin/cpp ${TMPPATH}/lib
sudo ln -sv gcc ${TMPPATH}/bin/cc
sudo install -v -dm755 ${TMPPATH}/lib/bfd-plugins
sudo ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/${TMPVER}/liblto_plugin.so \
${TMPPATH}/lib/bfd-plugins/

Note that the following version numbers may change with future versions of GCC. This is correct as of this writing. You can check by running ls ${TMPPATH}/lib64/libstdc++* or ls ${TMPPATH}/lib/libstdc++*.

sudo ln -sfv ${TMPPATH}/lib64/libstdc++.so.6.0.24-gdb.py \
/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.24-gdb.py
sudo ln -sfv ${TMPPATH}/lib64/libstdc++.so.6.0.24-gdb.py \
/usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.24-gdb.py
sudo ln -sv ../bin/cpp ${TMPPATH}/lib
sudo ln -sv gcc ${TMPPATH}/bin/cc
sudo install -v -dm755 ${TMPPATH}/lib/bfd-plugins
sudo ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/${TMPVER}/liblto_plugin.so \
${TMPPATH}/lib/bfd-plugins/

Note that the following version numbers may change with future versions of GCC. This is correct as of this writing. You can check by running ls ${TMPPATH}/lib64/libstdc++* or ls ${TMPPATH}/lib/libstdc++*.

sudo ln -sfv ${TMPPATH}/lib64/libstdc++.so.6.0.25-gdb.py \
/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.25-gdb.py
sudo ln -sfv ${TMPPATH}/lib64/libstdc++.so.6.0.25-gdb.py \
/usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.25-gdb.py
sudo ln -sv ../bin/cpp ${TMPPATH}/lib
sudo ln -sv gcc ${TMPPATH}/bin/cc
sudo install -v -dm755 ${TMPPATH}/lib/bfd-plugins
sudo ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/${TMPVER}/liblto_plugin.so \
${TMPPATH}/lib/bfd-plugins/

Note that the following version numbers may change with future versions of GCC. This is correct as of this writing. You can check by running ls ${TMPPATH}/lib64/libstdc++* or ls ${TMPPATH}/lib/libstdc++*.

sudo ln -sfv ${TMPPATH}/lib64/libstdc++.so.6.0.28-gdb.py \
/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.28-gdb.py
sudo ln -sfv ${TMPPATH}/lib64/libstdc++.so.6.0.28-gdb.py \
/usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.28-gdb.py

Check that cc is pointing to the new version with:

${TMPPATH}/bin/cc -v

Test the installation with:

cd ~
echo 'int main(){}' > dummy.c
${TMPPATH}/bin/cc dummy.c -v -Wl,--verbose &> dummy.log
readelf -l a.out | grep ': /lib'

That last command should output something like:

[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]

Now do:

grep -o '/lib.*/crt[1in].*succeeded' dummy.log

Which should output (note that .. may be replaced by something like x86_64-linux-gnu or something else depending on your distribution):

/lib/../lib64/crt1.o succeeded
/lib/../lib64/crti.o succeeded
/lib/../lib64/crtn.o succeeded

And now:

grep -B5 '^ /usr/include' dummy.log

Which should return (allowing for differences in architecture and GCC version number) the following. The important thing is that the include path of your newly-installed version appears first.

#include <...> search starts here:
 /opt/gcc6/lib/gcc/x86_64-pc-linux-gnu/6.5.0/include
 /usr/local/include
 /opt/gcc6/include
 /opt/gcc6/lib/gcc/x86_64-pc-linux-gnu/6.5.0/include-fixed
 /usr/include

Do some housecleaning:

sudo mv gcc-${TMPVER} /usr/local/src/
rm -v a.out dummy.c dummy.log gmp-*.tar* mpfr-*.tar* \
mpc-*.tar* isl-*.tar* gcc-*.tar*

Final Notes

It is a really good idea to reboot your system now:

sudo reboot

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.