How to Install gcc 5.3 with yum on CentOS 7.2?

171,579

Solution 1

Update:
Often people want the most recent version of gcc, and devtoolset is being kept up-to-date, so maybe you want devtoolset-N where N={4,5,6,7...}, check yum for the latest available on your system). Updated the cmds below for N=7.

There is a package for gcc-7.2.1 for devtoolset-7 as an example. First you need to enable the Software Collections, then it's available in devtoolset-7:

sudo yum install centos-release-scl
sudo yum install devtoolset-7-gcc*
scl enable devtoolset-7 bash
which gcc
gcc --version

Solution 2

Update: Installing latest version of gcc 9: (gcc 9.3.0) - released March 12, 2020:

Same method can be applied to gcc 10 (gcc 10.1.0) - released May 7, 2020

Download file: gcc-9.3.0.tar.gz or gcc-10.1.0.tar.gz

Compile and install:

//required libraries: (some may already have been installed)
dnf install libmpc-devel mpfr-devel gmp-devel

//if dnf install libmpc-devel is not working try:
dnf --enablerepo=PowerTools install libmpc-devel

//install zlib
dnf install zlib-devel*

./configure --with-system-zlib --disable-multilib --enable-languages=c,c++

make -j 8 <== this may take around an hour or more to finish
              (depending on your cpu speed)

make install

Tested under CentOS 7.8.2003 for gcc 9.3 and gcc 10.1

Tested under CentOS 8.1.1911 for gcc 10.1 (may take more time to compile)

Results: gcc/g++ 9.3.0/10.1.0

enter image description here enter image description here

Installing gcc 7.4 (gcc 7.4.0) - released December 6, 2018:

Download file: https://ftp.gnu.org/gnu/gcc/gcc-7.4.0/gcc-7.4.0.tar.gz

Compile and install:

//required libraries:
yum install libmpc-devel mpfr-devel gmp-devel

./configure --with-system-zlib --disable-multilib --enable-languages=c,c++

make -j 8 <== this may take around 50 minutes or less to finish with 8 threads
              (depending on your cpu speed)


make install

Result:

enter image description here

Notes:

1. This Stack Overflow answer will help to see how to verify the downloaded source file.

2. Use the option --prefix to install gcc to another directory other than the default one. The toplevel installation directory defaults to /usr/local. Read about gcc installation options

Solution 3

You can use the centos-sclo-rh-testing repo to install GCC v7 without having to compile it forever, also enable V7 by default and let you switch between different versions if required.

sudo yum install -y yum-utils centos-release-scl;
sudo yum -y --enablerepo=centos-sclo-rh-testing install devtoolset-7-gcc;
echo "source /opt/rh/devtoolset-7/enable" | sudo tee -a /etc/profile;
source /opt/rh/devtoolset-7/enable;
gcc --version;

Solution 4

The best approach to use yum and update your devtoolset is to utilize the CentOS SCLo RH Testing repository.

yum install centos-release-scl-rh
yum --enablerepo=centos-sclo-rh-testing install devtoolset-7-gcc devtoolset-7-gcc-c++

Many additional packages are also available, to see them all

yum --enablerepo=centos-sclo-rh-testing list devtoolset-7*

You can use this method to install any dev tool version, just swap the 7 for your desired version. devtoolset-6-gcc, devtoolset-5-gcc etc.

Share:
171,579

Related videos on Youtube

sunshine
Author by

sunshine

Updated on July 08, 2022

Comments

  • sunshine
    sunshine almost 2 years

    I am using CentOS 7.2

    When I use yum groupinstall "Development Tools", gcc version is 4.8.5, like this:

    enter image description here

    I would like to install gcc 5.3

    How to approach this with yum?

    • Mohammad Shahadat Hossain
      Mohammad Shahadat Hossain about 8 years
    • sunshine
      sunshine about 8 years
      @MohammadShahadatHossain Is there a yum resource anywhere?
    • Mohammad Shahadat Hossain
      Mohammad Shahadat Hossain about 8 years
      I am not sure but In this case you can use RPM resource from here. rpmfind.net/linux/rpm2html/search.php?query=gcc
    • tesch1
      tesch1 over 7 years
      devtoolset now provides 5.3.1 -- see my answer below for the commands to enable and install it using yum.
  • Keith Thompson
    Keith Thompson about 8 years
    Why download from ftp.mirrorservice.org rather than ftp.gnu.org? You should also download and verify the corresponding .sig file (the pgp signature).
  • tim18
    tim18 about 8 years
    Configuring as shown without --prefix will install in /usr/local/ which may or may not come ahead of your original gcc installation on PATH
  • tesch1
    tesch1 over 7 years
    the gcc version in devtoolset has in the mean time been bumped to 5.3.1
  • Rahly
    Rahly about 7 years
    Not only that, but you can install devtoolset-6 to get 6.2.1
  • Maksym Ganenko
    Maksym Ganenko almost 7 years
    Thanks, you saved my day! Also, I see that my /usr/bin/c++ is still linked to gcc 4.8.5, so I had to relink to gcc 6: ln -sf /opt/rh/devtoolset-6/root/usr/bin/g++ /usr/bin/c++
  • tesch1
    tesch1 almost 7 years
    changing the symlink isn't the best thing to do, since it's probably owned/managed by another package that could get upgraded. It's better to activate it in your login, or in the system-wide login script with scl enable devtoolset-6 bash or . /opt/rh/devtoolset-6/bin/enable updated link to software tools docs
  • scrutari
    scrutari over 6 years
    Running yum install devtoolset-4-binutils might be helpful as well to get complete GCC toolchain.
  • Chepe Questn
    Chepe Questn over 6 years
    make -j $(nproc)
  • iDevFS
    iDevFS over 6 years
    This took me over 4 hours to compile and more than 6gb of HDD space.
  • W.F.
    W.F. over 6 years
    I used source scl_source enable devtoolset-4 to switch my current gcc with the one installed by devtoolset-4
  • Marián Černý
    Marián Černý over 6 years
    Use devtoolset-6, because devtoolset-4 is End of life.
  • TriskalJM
    TriskalJM over 6 years
    devtoolset-6 now has gcc 6.3.1
  • Celdor
    Celdor about 6 years
    As tim18 suggested, is it safe to run make && make install without --prefix? If do so, everything is installed into /usr/ not even /usr/local, check the config.log: Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info ...
  • B. Shea
    B. Shea almost 6 years
    I see 4,6,7 on mine. Why no 5?
  • Robert Columbia
    Robert Columbia over 5 years
    While this code may answer the question, it is better to explain how to solve the problem and provide the code as an example or reference. Code-only answers can be confusing and lack context.
  • Rob T.
    Rob T. about 5 years
    Just do a yum install devtoolset-8 without anything after that. The devtoolset-N packages are meta packages that install the default packages and pull in the necessary dependencies
  • Daniel Schepler
    Daniel Schepler about 5 years
    Note that you will not be able to put binaries compiled with a gcc compiled in this way into an RPM (at least with the default RPM environment). I needed to add --enable-linker-build-id before that would work.
  • Stepan Yakovenko
    Stepan Yakovenko almost 5 years
    this answer doesn't work any more, it installs gcc 7
  • Stepan Yakovenko
    Stepan Yakovenko almost 5 years
    this answers other question
  • HDJEMAI
    HDJEMAI almost 5 years
    @StepanYakovenko: My answer includes installing gcc 5.3 but I deleted it recently because no one will search to install an old gcc version, and this method still work for that if some one needs it.
  • HDJEMAI
    HDJEMAI almost 5 years
    This answer still works, it's up to you to choose the right version of devtoolset to install.
  • HDJEMAI
    HDJEMAI almost 5 years
  • Shixiang Wang
    Shixiang Wang almost 5 years
    How can I use g++7 as default, when I open a new terminal, it is still v4.8.5
  • tesch1
    tesch1 almost 5 years
    you need to scl enable devtoolset-7 bash every time you open a new shell, or add it to your *rc
  • Ask_SO
    Ask_SO about 4 years
    @HDJEMAI - Could you please help me on stackoverflow.com/questions/61831832/…
  • Fafaman
    Fafaman about 4 years
    devtoolset-5 does not exists on centos7 hence the answer does not apply to the op question.
  • scaly
    scaly about 4 years
    Sadly this solution does not update the /usr/lib64/libstdc++.so file to have the newer symbols.
  • scaly
    scaly almost 4 years
    I installed devtoolset-9 but this does nothing at all... /usr/lib64/libstdc++.so.6 is still the ancient version. The libstdc++.so inside devtoolset-9 is just a few characters that links back to the useless /usr/lib64/libstdc++.so.6. Turns out you have to use podman to do anything with c++ in devtoolset, but I can't because I'm already operating inside a docker container and so podman can't do jack. So this whole piece of crap OS is useless.
  • hunter_tech
    hunter_tech almost 3 years
    It could work for me. The system still use the old version of gcc placed on the directory /usr/bin/gcc.
  • Bruce Adams
    Bruce Adams about 2 years
    The procedure on RHEL7 is similar but more painful. See stackoverflow.com/a/72002572/1569204
  • nt86
    nt86 about 2 years
    @Fafaman - there is inconsistency in versions, actually devtoolset-4 contains gcc 5.3.1, and dev-toolset-5 doesn't exist.