How to Install gcc 5.3 with yum on CentOS 7.2?
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
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:
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.
Related videos on Youtube
sunshine
Updated on July 08, 2022Comments
-
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:I would like to install gcc 5.3
How to approach this with
yum
?-
Mohammad Shahadat Hossain about 8 yearsfollow this tutorial vultr.com/docs/how-to-install-gcc-on-centos-6
-
sunshine about 8 years@MohammadShahadatHossain Is there a
yum
resource anywhere? -
Mohammad Shahadat Hossain about 8 yearsI am not sure but In this case you can use RPM resource from here. rpmfind.net/linux/rpm2html/search.php?query=gcc
-
tesch1 over 7 yearsdevtoolset now provides 5.3.1 -- see my answer below for the commands to enable and install it using yum.
-
-
Keith Thompson about 8 yearsWhy download from ftp.mirrorservice.org rather than ftp.gnu.org? You should also download and verify the corresponding
.sig
file (the pgp signature). -
tim18 about 8 yearsConfiguring as shown without --prefix will install in /usr/local/ which may or may not come ahead of your original gcc installation on PATH
-
tesch1 over 7 yearsthe gcc version in devtoolset has in the mean time been bumped to 5.3.1
-
Rahly about 7 yearsNot only that, but you can install devtoolset-6 to get 6.2.1
-
Maksym Ganenko almost 7 yearsThanks, 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 almost 7 yearschanging 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 over 6 yearsRunning
yum install devtoolset-4-binutils
might be helpful as well to get complete GCC toolchain. -
Chepe Questn over 6 years
make -j $(nproc)
-
iDevFS over 6 yearsThis took me over 4 hours to compile and more than 6gb of HDD space.
-
W.F. over 6 yearsI used
source scl_source enable devtoolset-4
to switch my current gcc with the one installed bydevtoolset-4
-
Marián Černý over 6 yearsUse devtoolset-6, because devtoolset-4 is End of life.
-
TriskalJM over 6 years
devtoolset-6
now hasgcc 6.3.1
-
Celdor about 6 yearsAs 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 theconfig.log
:Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info ...
-
B. Shea almost 6 yearsI see 4,6,7 on mine. Why no 5?
-
Robert Columbia over 5 yearsWhile 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. about 5 yearsJust 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 about 5 yearsNote 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 almost 5 yearsthis answer doesn't work any more, it installs gcc 7
-
Stepan Yakovenko almost 5 yearsthis answers other question
-
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 almost 5 yearsThis answer still works, it's up to you to choose the right version of devtoolset to install.
-
HDJEMAI almost 5 yearsuse ftp.gnu.org/pub/gnu/gcc/gcc-5.3.0/gcc-5.3.0.tar.bz2 if you want gcc 5.3
-
Shixiang Wang almost 5 yearsHow can I use g++7 as default, when I open a new terminal, it is still v4.8.5
-
tesch1 almost 5 yearsyou need to
scl enable devtoolset-7 bash
every time you open a new shell, or add it to your *rc -
Ask_SO about 4 years@HDJEMAI - Could you please help me on stackoverflow.com/questions/61831832/…
-
Fafaman about 4 yearsdevtoolset-5 does not exists on centos7 hence the answer does not apply to the op question.
-
scaly about 4 yearsSadly this solution does not update the
/usr/lib64/libstdc++.so
file to have the newer symbols. -
scaly almost 4 yearsI 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 almost 3 yearsIt could work for me. The system still use the old version of gcc placed on the directory /usr/bin/gcc.
-
Bruce Adams about 2 yearsThe procedure on RHEL7 is similar but more painful. See stackoverflow.com/a/72002572/1569204
-
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.