I am trying to install gcc and g++ 4.9.2 on Linux. I'm pretty new with Linux and i saw some guides of how to install, but each time I encountered with another problem. I don't have any gcc right now on my machine. my Linux version is: Red Hat Enterprise Linux Server release 7.4 (Maipo) can someone help me and give me instructions from the beginning to the end how to do this properly? thank you very much.
4 Answers
yum install centos-release-scl-rh
yum install devtoolset-3-gcc devtoolset-3-gcc-c++
update-alternatives --install /usr/bin/gcc-4.9 gcc-4.9 /opt/rh/devtoolset-3/root/usr/bin/gcc 10
update-alternatives --install /usr/bin/g++-4.9 g++-4.9 /opt/rh/devtoolset-3/root/usr/bin/g++ 10

- 4,940
- 6
- 45
- 63
-
5seems we need to make devtoolset-3 work in bash after install. `source scl_source enable devtoolset-3` – hakunami Jun 12 '18 at 06:22
-
2@hakunami : `$ scl enable devtoolset-3 bash` https://www.softwarecollections.org/en/scls/rhscl/devtoolset-3/ – Knud Larsen Jun 13 '18 at 08:05
-
FYI: `devtoolset-3` was EOL on Oct 2016. If you need the newer version of GCC, check the latest `sevtoolset` version in the Software Collections site: https://www.softwarecollections.org/en/scls/user/rhscl/?search=devtoolset&policy=&repo=&order_by=-create_date&per_page=10 – shuuji3 Sep 03 '19 at 11:06
For installing the system compilers gcc, g++, the install command is # yum install gcc-c++
→ Provides version 4.8.5 : /usr/bin/{ gcc, g++ }
.
Other options: 1. gcc53-c++-5.3.0-1.el6.x86_64.rpm → https://drive.google.com/file/d/0B7S255p3kFXNRm9FVnZYUnhyZzg/view?usp=sharing&resourcekey=0-1N6zQa6Sbl_WycG1O9I7JA : Download and install : # cd Downloads/ && yum install ./gcc53-c++-5.3.0-1.el6.x86_64.rpm
..... Provides /usr/bin/{gcc53, g++53}
.
- The devtoolset´s : https://www.softwarecollections.org/en/scls/rhscl/devtoolset-6/ →
# yum-config-manager --enable rhel-server-rhscl-7-rpms
Install gcc, g++ version 4.9.2 : # yum install devtoolset-3-gcc-c++
Note : You can have as many gcc/g++ versions as you want, installed at the same time. ( The system compilers are a must.)
- gcc49-c++-4.9.3-1.el6.x86_64.rpm https://drive.google.com/file/d/1Pwq1ua80dGM72i7rpDNAIIdfcR1WK-hG/view?usp=sharing → Provides
/usr/bin/{gcc49, g++49}
.
gcc63-c++-6.3.0-1.el7.x86_64.rpm https://drive.google.com/file/d/1t4WrgvpEP-6_NN3qMJhz9MS3CJhHrHKc/view?usp=sharing → Provides
/usr/bin/{gcc63, g++63}
.gcc45-c++-4.5.4-1.el7.x86_64.rpm https://drive.google.com/file/d/15aRg-BPhuyaEyZA9Jy-iAyC21_pwN7nD/view?usp=sharing → Provides
/usr/bin/{gcc45, g++45, gfortran45}
gcc42-c++-4.2.4-1.el6.x86_64.rpm https://drive.google.com/file/d/1eYWk6Nd63xeqqAUoJldNWRuwEGO6cAyv/view?usp=sharing → Provides
/usr/bin/{gcc42, g++42}
gcc73-c++-7.3.0-1.el7.x86_64.rpm https://drive.google.com/file/d/1PgwCP5tu8D0EJbJVTqJd7Vg8dJ4l4noi/view?usp=sharing → Provides
/usr/bin/{gcc73, g++73}
gcc48-c++-4.8.5-1.el6.x86_64.rpm https://drive.google.com/file/d/1w6fW6oSflDDYZt_cOpGj3QMEmzUC8Q9L/view?usp=sharing → Provides
/usr/bin/{gcc48, g++48, gfortran48}
gcc84-c++-8.4.0-1.el7.x86_64.rpm https://drive.google.com/file/d/1xgFtsiDi2uiB1B0AcOaSpxVizzET-pJf/view?usp=sharing → Provides
/usr/bin/{gcc84, g++84, gfortran84}

- 5,753
- 2
- 14
- 19
-
2thank you, your answer is very helpful but I have one more question. if I want to install gcc 6.2 for say, how can I find this particular version of compiler? because you gave me one option to install c++-5.3-1. where do I find other versions to choose? – Hope Nov 09 '17 at 13:21
-
The above `devtoolset-6` link : Click CentOS 7 → http://mirror.centos.org/centos/7/sclo/x86_64/rh/ → **devtoolset -3 -4 -6 -7** : devtoolset-6 has gcc-6.3.1 : `# yum install devtoolset-6-gcc-c++` : gcc-6 a.o. will automatically be installed as dependencies. http://mirror.centos.org/centos/7/sclo/x86_64/rh/devtoolset-6/ . ....... About gcc53-c++-5.3.0-1.el6.x86_64.rpm : Provides /usr/bin/{gcc53, g++53}. – Knud Larsen Nov 10 '17 at 01:46
-
@KnudLarsen, your resources are great, but can you provide a step-by-step instruction, how to compile new gcc that will use old libs from standart CentOS 7 installation? Maybe there is some link on such instruction already exists? It will be very helpful. – unibasil Nov 11 '19 at 06:20
-
I'm actually on fedora 31 and I would like to have gcc-8, I tried downloading from pkgs.org but I'm stuck in a dependencies hell, a self contained package like those you linked would really be appreciated – RMPR Nov 14 '19 at 13:52
-
@KnudLarsen I have a more formal question [here](https://stackoverflow.com/questions/58859081/how-to-install-an-older-version-of-gcc-on-fedora) can you write a more detailed answer ? – RMPR Nov 14 '19 at 14:52
-
@KnudLarsen I try install gcc/g++ 4.8.5 on centos8.1, However I can't install it. I need one package .rpm for gcc/g++ 4.8.5 on centos8.1. Can you help me? thank you – Tung Duong Oct 14 '20 at 09:10
-
@KnudLarsen I wan to install gcc/g++ 4.8.5 on Ubuntu 20.04. But Ubuntu 20.04 not support repository for install gcc4.8.5 . Can you help me? If you have guide for build gcc on OS Linux, you can send to me. I will build it. Thank you. – Tung Duong Nov 19 '20 at 06:04
-
Dear @KnudLarsen , On CentOS7 have package "devtoolset-8". However gcc/g++ in this package is gcc/g++ 8.3.x. - I had used gcc/g++ 8.3.x compile for my project, I got an error "internal compiler error: in type_dependent_expression_p, at cp/pt.c " - However on Ubuntu 18.04, If I use gcc/g++ 8.4.x compile for my project. My project build successful. I guess gcc/g++ 8.3.1 have issue ? Please help me build package rpm gcc/g++ 8.4.x on centos7. Thank you ! – Tung Duong Mar 29 '21 at 09:46
-
Thanks buddy. I built successful with gcc/g++7.3.x. However I want my project build on gcc/g++8. Do you know which version of gcc/g++8 on CentOS doesn't meet the "internal compiler error" like gcc/g++8.4.x on Ubuntu ? @KnudLarsen – Tung Duong Mar 30 '21 at 10:29
-
Thank you ! Your package at item 9 ```gcc84-c++-8.4.0-1.el7.x86_64.rpm``` is ok. I will use it. – Tung Duong Mar 31 '21 at 07:28
-
Always be careful installing pre-built packages from unknown sources. – user2066657 Jul 16 '21 at 16:31
-
@KnudLarsen, Please, provide the source rpm for packages gcc73-c++-7.3.0-1.el7.x86_64.rpm and gcc84-c++-8.4.0-1.el7.x86_64.rpm. Thank you! – phprus Nov 03 '21 at 19:20
RHEL comes with preconfigured repo, you can search for the desired packages and install them using yum package manager.
To do so, first run ( to search gcc
)
$ sudo yum search gcc
which will show you a list of available packages with the matching name
============================ Name Exactly Matched: gcc =============================
gcc.x86_64 : Various compilers (C, C++, Objective-C, ...)
gcc.x86_64 : Various compilers (C, C++, Objective-C, ...)
gcc.i686 : Various compilers (C, C++, Objective-C, ...)
=========================== Name & Summary Matched: gcc ============================
gcc-c++.x86_64 : C++ support for GCC
gcc-c++.i686 : C++ support for GCC
gcc-gdb-plugin.x86_64 : GCC plugin for GDB
gcc-gdb-plugin.i686 : GCC plugin for GDB
gcc-gdb-plugin.x86_64 : GCC plugin for GDB
gcc-objc.x86_64 : Objective-C support for GCC
...
Install the package you need by running ( to install gcc-c++
)
$ sudo yum install gcc-c++
It will the packages to be installed and ask for confirmation.
Dependencies resolved.
====================================================================================
Package Architecture Version Repository Size
====================================================================================
Installing:
gcc-c++ x86_64 8.3.1-2.fc29 updates 12 M
Transaction Summary
====================================================================================
Install 1 Package
Total download size: 12 M
Installed size: 29 M
Is this ok [y/N]:
NOTE: Steps mentioned above will install latest available version of the package.
Install a particular Version of a Package
Install all development tools

- 1,616
- 1
- 14
- 23
-
6thanks, I installed it and it worked but i wanted gcc 4.9.2 but when I checked it (with the command: gcc --vesion) I got: gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16) also I have tried to install g++ in the same way: yum install g++ and this isn't work. how does it work with g++? – Hope Nov 08 '17 at 10:11
-
First search for the package you want by doing for example `yum search gcc-c++` you will get a list of available packages, then install the package mentioning the correct name. – Vipin Yadav Nov 08 '17 at 10:23
-
1I did the search but I didn't see the version of each compiler. I can see only the names. – Hope Nov 12 '17 at 09:05
-
This link : http://mirror.centos.org/centos/7/sclo/x86_64/rh/ ... will show { devtoolset-3/, devtoolset-4/, devtoolset-6/, devtoolset-7/ } links , click a link and look for devtoolset-*-gcc-c++ . But then again : You can use `# yum search gcc-c++` to know what's available. ( If you have run `# yum-config-manager --enable rhel-server-rhscl-7-rpms` ) – Knud Larsen Nov 12 '17 at 20:19
-
https://unix.stackexchange.com/questions/63587/how-to-install-g-4-7-2-c11-on-centos-5-x Check this. – Vipin Yadav Nov 13 '17 at 04:23
-
6I finally succeeded installe it. this way: sudo yum install centos-release-scl sudo yum install devtoolset-6 scl enable devtoolset-6 bash So I have gcc 7.2.1 on my machine. But now I have another problem. the old gcc executable file was run over by the new one and now I can't use the previous version of the gcc. Is there a way to solve this? – Hope Nov 16 '17 at 10:39
-
1It is better to avoid overriding default gcc compiler on RHEL 7 as other programs compiled using GCC < 4.9 may throw an error with version mismatch for a shared gcc/g++ library. Better approach is one suggested by @Lars-Bilke below. Only caveat being to load GCC 4.9 environment with `scl enable devtoolset-3 bash` before loading program you compiled using GCC 4.9 library. – Samir Jul 09 '19 at 04:55