CentOS 8 already comes with GCC 8.
On CentOS 7, you can install GCC 8 from Developer Toolset. First you need to enable the Software Collections repository:
yum install centos-release-scl
Then you can install GCC 8 and its C++ compiler:
yum install devtoolset-8-gcc devtoolset-8-gcc-c++
To switch to a shell which defaults gcc and g++ to this GCC version, use:
scl enable devtoolset-8 -- bash
You need to wrap all commands under the scl call, so that the process environment changes performed by this command affect all subshells. For example, you could use the scl command to invoke a shell script that performs the required actions.
CentOS 8 already comes with GCC 8.
On CentOS 7, you can install GCC 8 from Developer Toolset. First you need to enable the Software Collections repository:
yum install centos-release-scl
Then you can install GCC 8 and its C++ compiler:
yum install devtoolset-8-gcc devtoolset-8-gcc-c++
To switch to a shell which defaults gcc and g++ to this GCC version, use:
scl enable devtoolset-8 -- bash
You need to wrap all commands under the scl call, so that the process environment changes performed by this command affect all subshells. For example, you could use the scl command to invoke a shell script that performs the required actions.
Permanently adding DTS to your development environment
After installing the devtoolset:
yum install devtoolset-8-gcc devtoolset-8-gcc-c++
You can also use the following command, to make DTS the default:
source scl_source enable devtoolset-8
The benefit of this command is that it can be added to .bashrc, so that you don't have to run the scl command every time you login:
scl enable devtoolset-8 -- bash
c++ - Install older gcc/g++ versions in CentOS 8 - Stack Overflow
linux - Installing older package of gcc on Centos 8 via dnf - Unix & Linux Stack Exchange
c++ - Compile old gcc version on Centos 8 - Stack Overflow
c++ - How to install gcc/g++ 9 on CentOS 8 docker (centos:latest) - Stack Overflow
If you wish to install an older gcc than the distro provides, you will need to compile it for source.
There is some guidance below on how to download and build an old GCC
https://bytefreaks.net/gnulinux/downgrade-gcc-on-centos-7-0-64bit-to-version-4-8-2
Found a solid path that has automated compiling and packaging gcc, as well as a guide:
- Guide:
- https://bobsteagall.com/2017/12/30/gcc-builder/
- Github repo:
- https://github.com/BobSteagall/gcc-builder
I won't copy paste what's in this person's guide as they deserve the credit. However, here's a summary of the steps:
- Install your prereqs (rpm build tools, devtools for bootstrapping your environment).
- Clone the repo.
- Checkout a branch in the repo like the major version of GCC you want (e.g.
gcc7). - In the repo, edit
gcc-build-vars.shsuch that it points to a version of GCC you want fromhttp://gnu.mirror.constant.com/gcc/. - Perform the build with:
./build-gcc.sh -T | tee build.log. - Stage it:
./stage-gcc.sh. - Package it: (
./pack-gcc.shor./make-gcc-rpm.sh -v).
Simply use dnf
Copydnf -y install gcc-toolset-9-gcc gcc-toolset-9-gcc-c++
source /opt/rh/gcc-toolset-9/enable
ref: https://centos.pkgs.org/8/centos-appstream-x86_64/gcc-toolset-9-gcc-9.1.1-2.4.el8.x86_64.rpm.html
Note: source won't work inside a Dockerfile so prefer to use:
CopyENV PATH=/opt/rh/gcc-toolset-9/root/usr/bin:$PATH
or better
CopyRUN dnf -y install gcc-toolset-9-gcc gcc-toolset-9-gcc-c++
RUN echo "source /opt/rh/gcc-toolset-9/enable" >> /etc/bashrc
SHELL ["/bin/bash", "--login", "-c"]
RUN gcc --version
this command work for me
Copydnf install gcc --best --allowerasing
Edit: What happened? When I went to download centos I mistakenly understood centos 7 as being the most recent stable version. Original post below:
Ok, I have only used the mint distro as of yet (for about a year now). I wanted to start getting to know other distros so I repaired an older funky pc's power supply and changed out the windows 7 on it for Centos with Gnome desktop just yesterday. So Centos is new to me and mint has been my experience (but I am still a novice with it).
I checked out the GCC and it's version 4.8.5 . On my mint laptop I was able to install version 10.3.0 through the apt package manager. The search results I get from using yum though do not seem to spit out anything similar as far as I can tell. And the google searches I do seem to all point towards installing from source.
But a friend of mine the other day when discussing how I used my laptop in mint was very emphatic that I should avoid as much as possible installing anything from source that was available already through a package manager, saying that when things later become updated it is much safer and less of a mess to have the package manager handle the changes.
So my noob question is this... Does that type of thinking not apply to the Centos distro? Or is the purpose of Centos less intended for developers? Or something else?
In the end I am too ignorant in this current situation to really know what I am ignorant of so bottom line question is:
In Centos 7 What is the most recommended way to upgrade GCC?
Thanks