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 sed -i 's/enabled=0/enabled=1/' /etc/yum.repos.d/CentOS-Sources.repo
sudo dnf groupinstall "Development Tools"

sudo dnf install autogen bzip2 bzip2-devel cmake cvs \
cyrus-sasl-scram dejagnu dkms doxygen dpkg fakeroot gcc gperf \
java-1.8.0-openjdk-devel kernel-devel-$(uname -r) libaio-devel \
libmpc-devel libtirpc-devel libzstd-devel make mercurial nano \
ncurses-devel openldap-devel openssl-devel patchelf perl python2-devel \
python3 python3-devel python3-pip python38 python38-pip qt5-qtbase-devel \
rpcgen setroubleshoot-server sphinx svn tex texinfo wget

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

sudo dnf install autogen bzip2 bzip2-devel bzip2-static cmake cvs \
cyrus-sasl-scram dejagnu dkms doxygen dpkg fakeroot gcc gperf \
java-devel Judy Judy-devel kernel-devel-$(uname -r) libaio-devel \
libmpc-devel libtirpc-devel libzstd-devel make mercurial nano \
ncurses-devel openldap-devel openssl-devel patchelf perl python2 \
python2-devel python3-devel python3-pip qt5-qtbase-devel \
rpcgen setroubleshoot-server sphinx svn tex texinfo wget
sudo dpkg --add-architecture i386

sudo apt update

sudo apt install build-essential

sudo apt install aspell autoconf autogen automake binutils-dev bison \
checkpolicy cmake dejagnu doxygen equivs expect flex freetds-bin \
freetds-dev gdb glibc-source gnat gnulib gnutls-dev gperf gprbuild \
guile-3.0 libaio-dev libboost-all-dev libbz2-dev libc-client-dev \
libcpprest-dev libcrack2-dev libcurl4 libcurl4-openssl-dev \
libdbd-mysql-perl libdbi-perl libedit-dev libexpat-dev libfreetype-dev \
libgroonga-dev libjemalloc-dev libjpeg9 libjpeg9-dev libjudy-dev \
libkrb5-dev liblz4-dev liblz4-tool liblzma-dev liblzo2-dev \
libmcrypt-dev libmcrypt4 libmecab-dev libmongoc-dev libmsgpack-dev \
libncurses5 libncurses5-dev libncursesw5-dev libpcre2-dev libpcre3-dev \
libreadline-dev libstdc++-10-dev libstemmer-dev libsnappy-dev libsnappy1v5 \
libsystemd-dev libthrift-dev libtidy-dev libtirpc-dev libtommath-dev \
libtool libxml2-dev libxml2-utils libxpm-dev libxslt-dev libzmq5-dev \
linux-headers-$(uname -r) lynx nano openjdk-8-jdk re2c ruby semodule-utils \
subversion systemtap-sdt-dev texlive unixodbc-dev uuid-dev uw-mailutils \
valgrind xinetd
sudo dpkg --add-architecture i386

printf \
"deb https://packages.groonga.org/debian/ stretch main\ndeb-src https://packages.groonga.org/debian/ stretch main" \
| sudo tee /etc/apt/sources.list.d/groonga.list

sudo apt install --allow-unauthenticated groonga-keyring

sudo apt update

sudo apt install build-essential

sudo apt install apt-transport-https aspell autoconf autogen automake \
binutils-dev bison cmake default-jdk-headless dejagnu doxygen equivs expect \
flex freetds-bin freetds-dev gdb glibc-source gnat gnulib gnutls-dev gperf \
gprbuild guile-2.0 libaio-dev libaspell-dev libboost-all-dev libbz2-dev \
libc-client-dev libcrack2-dev libcurl4 libcurl4-openssl-dev \
libdbd-mysql-perl libdbi-perl libedit-dev libevent-dev libexpat-dev \
libfreetype6-dev libgroonga-dev libjemalloc-dev libjpeg-dev libjpeg62-turbo \
libjpeg62-turbo-dev libjudy-dev libkrb5-dev liblz4-dev liblz4-tool \
liblzo2-dev libmcrypt-dev libmcrypt4 libmecab-dev libmsgpack-dev \
libncurses5 libncurses5-dev libncursesw5-dev libpcre2-dev libpcre3-dev \
libreadline-dev libstdc++-8-dev libstemmer-dev libsnappy-dev libsnappy1v5 \
libsystemd-dev libtidy-dev libtirpc-dev libtommath-dev libxml2-dev \
libxpm-dev libxslt-dev libzmq5-dev linux-headers-$(uname -r) lynx nano re2c \
subversion systemtap-sdt-dev texlive unixodbc-dev uuid-dev uw-mailutils \
valgrind xinetd
sudo zypper refresh

sudo zypper update

sudo zypper install -t pattern devel_C_C++

sudo zypper install aspell aspell-devel autoconf autogen automake \
binutils-devel bison libboost_headers1_66_0-devel cmake cracklib-devel \
dejagnu dkms doxygen flex freetds-config freetds-devel freetype \
freetype-devel gcc-ada gcc-c++ gdb git gperf guile java-11-openj9-devel \
jemalloc-devel judy-devel krb5-devel \
kernel-default-devel=$(uname -r | sed 's/-default.*//g') libaio-devel \
libcurl-devel libevent-devel libexpat-devel libgnutls-devel libicu-devel \
libjpeg-devel libjpeg-turbo liblz4-devel libncurses5 libnuma-devel \
libpng16-devel libtidy5 libtidy-devel libtomcrypt0 libtomcrypt-devel \
libtommath-devel libtool libuuid-devel libxml2-devel libXpm-devel \
libxslt-devel lynx msgpack-devel nano openssl-devel pam-devel patch \
pcre-devel pcre2-devel perl-DBD-mysql re2c systemd-devel systemtap-sdt-devel \
texinfo unixODBC-devel valgrind-devel xinetd 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 aspell autogen boost boost-libs cmake cracklib dejagnu doxygen \
expect freetds freetype2 gcc-ada gdb git gperf inetutils jemalloc libaio \
libcrossguid libcurl-compat libevent libjpeg-turbo libmcrypt libstdc++5 \
libstemmer libtommath libxpm libxslt \
linux-headers=$(uname -r | sed 's/-ARCH.*//g' | sed 's/-arch/.arch/g') lynx \
lzo msgpack-c nano numactl perl-dbd-mysql perl-dbi re2c rpcsvc-proto svn tidy \
valgrind zeromq 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"
sudo pacman -S python2 python2-setuptools cpio elfutils nss xmlto
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.3"
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.