User Tools

Site Tools


gcccompilerlinux

Compiler: Installing multiple GCC compilers on a CentOS 7 system with Tux

Hey, my name is "Tux"! Hey, my name is "Tux" and in this tutorial I will show you how you can get multiple GCC compilers on a single Linux system in case you need it running in parallel.

Let's waddle through it!



Start of tutorial

Installing required tools and a GCC compiler from default repository:

$ yum install git make gmp-devel mpfr-devel libmpc-devel
$ yum groupinstall "Development Tools"

Now navigate to the following directory:

$ cd /tmp

Download the desired GCC release:
Note: Replace the following placeholders <x> with the release number according to the desired GCC release:

$ curl https://ftp.gnu.org/gnu/gcc/gcc-<x>.<x>.<x>/gcc-<x>.<x>.<x>.tar.gz -O

Now decompress the downloaded package:

$ tar -zxvf gcc-<x>.<x>.<x>.tar.gz

Now create a temporary build directory:

$ mkdir gcc-<x>.<x>.<x>-build

Navigate into that build directory:

$ cd gcc-<x>.<x>.<x>-build

Execute Makefile configuration:

$ ../gcc-<x>.<x>.<x>/configure --enable-languages=c,c++ --disable-multilib --prefix=/usr/local/gcc-<x>.<x>.<x>

Start compiling:

$ make -j$(nproc) && make install

Now the installation should be done.
By going the described way it is possible to install multiple GCC compilers in parallel.
Now when it is required to set a specific compiler version for CMAKE there are two settings required to be set each time:
Beware: The following two settings are only applied temporary for the current session by the operating system. If it is required to set a specific default GCC version have a look on the info box Optional further down.

  1. Attaching the path of the desired GCC compiler version's executables in global path settings:

    $ export PATH=/usr/local/gcc-<x>.<x>.<x>/bin:$PATH

  2. Attaching the path of the desired GCC compiler version's Shared Libraries in global library path settings:

    $ export LD_LIBRARY_PATH=/usr/local/gcc-<x>.<x>.<x>/lib64:$LD_LIBRARY_PATH

Check whether the desired GCC version is being used by system now:

$ gcc --version

Optional

If it is required to set a specific default GCC compiler version for the operating system global path variables and global library path variables have to be set inside the following file:

$ vi /etc/profile

Add the following content:

export PATH=/usr/local/gcc-<x>.<x>.<x>/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/gcc-<x>.<x>.<x>/lib64:$LD_LIBRARY_PATH

Save the file and quit the editor.

Now reboot the system:

$ reboot -h now

Check whether the desired default GCC version is being used by system now:

$ gcc --version


End of tutorial



Appreciate my work?
Buy me a coffee or PayPal

gcccompilerlinux.txt · Last modified: