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.
3 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
-
5seems we need to make devtoolset-3 work in bash after install.
source scl_source enable devtoolset-3
– hakunamiJun 12, 2018 at 6:22 -
2@hakunami :
$ scl enable devtoolset-3 bash
softwarecollections.org/en/scls/rhscl/devtoolset-3 Jun 13, 2018 at 8:05 -
FYI:
devtoolset-3
was EOL on Oct 2016. If you need the newer version of GCC, check the latestsevtoolset
version in the Software Collections site: softwarecollections.org/en/scls/user/rhscl/…– shuuji3Sep 3, 2019 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}
-
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?– HopeNov 9, 2017 at 13:21
-
The above
devtoolset-6
link : Click CentOS 7 → 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. 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}. Nov 10, 2017 at 1: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.– unibasilNov 11, 2019 at 6: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– RMPRNov 14, 2019 at 13:52
-
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
-
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++?– HopeNov 8, 2017 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. Nov 8, 2017 at 10:23 -
1I did the search but I didn't see the version of each compiler. I can see only the names.– HopeNov 12, 2017 at 9:05
-
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?– HopeNov 16, 2017 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.– SamirJul 9, 2019 at 4:55