🌐
JWillikers
jwillikers.com › build-gcc-from-source-on-centos-7
Build GCC From Source on CentOS 7 - JWillikers
October 28, 2020 - ../gcc-10.2.0/configure --enable-languages=c,c++,fortran \ --disable-multilib --prefix=$HOME/.gcc/10.2.0 ... Wait patiently for GCC to finish compiling itself. Install GCC.
🌐
LinuxHostSupport
linuxhostsupport.com › home › how to install gcc on centos 7
How To Install GCC on CentOS 7 | LinuxHostSupport
May 24, 2019 - Run the following command to install GCC on your server ... gcc --version gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16) Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. As might be seen from the output, the GCC version distributed by CentOS 7 is 4.8.5 which is not the latest version of GCC.
Discussions

installation - How to Install gcc 5.3 with yum on CentOS 7.2? - Stack Overflow
Tested under CentOS 8.1.1911 for gcc 10.1 (may take more time to compile) ... //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... More on stackoverflow.com
🌐 stackoverflow.com
c++ - How to enable later versions of GCC in eclipse CDT in CentOS 7 - Stack Overflow
My CentOS 7 machine has a default GCC version of 4.8.5. I want to use a higher version of GCC. So, I executed the following steps in a terminal: sudo yum install centos-release-scl sudo yum install devtoolset-10-gcc* scl enable devtoolset-10 bash More on stackoverflow.com
🌐 stackoverflow.com
gcc - how to install gcc7 in docker centos7 - Stack Overflow
--with-default-libstdcxx-abi=new ... 2023-09-14T21:06:10.687Z+00:00 ... download_prereq need a tweak - using gcc.gnu.org/pub/gcc/infrastructure and --no-verify 2023-09-14T21:15:14.427Z+00:00 ... RUN yum install -y centos-release-scl RUN yum install -y devtoolset-7-gcc-* RUN echo ... More on stackoverflow.com
🌐 stackoverflow.com
How to install GCC/G++ 8 on CentOS - Stack Overflow
You can find more details for working ... so that gcc/g++ 8 will always be in your path. 2019-03-26T22:22:43.15Z+00:00 ... # yum install centos-release-scl No match for argument: centos-release-scl I'm using CentOS 8. Where can I get the packages installed here? 2020-01-16T12:22:08.223Z+00:00 ... It helps on CentOS 7. Just replace the 8 with 10 to install ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
The Linux Cluster
thelinuxcluster.com › 2022 › 07 › 01 › compiling-gcc-10-4-0-on-centos-7
Compiling GCC-10.4.0 on CentOS-7 – The Linux Cluster
July 1, 2022 - Step 1: Download the TarBall version of GCC version. If you want to take look at all the available versions, you can take a look at http://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/ For this blog entry, we will install GCC-10.4.0. ...
🌐
Wii Blog
wfeii.com › 2021 › 01 › 25 › centos7-gcc10.html
CentOS 7 编译安装 GCC 10.2.0
January 25, 2021 - $ tar -xvf gcc-10.2.0.tar.xz $ ... --enable-checking=release --enable-languages=c,c++ --disable-multilib $ make ... 数小时的等待 $ sudo make install...
🌐
nixCraft
cyberciti.biz › nixcraft › howto › centos › centos / rhel 7: install gcc (c and c++ compiler) and development tools
CentOS / RHEL 7: Install GCC (C and C++ Compiler) and Development Tools - nixCraft
April 5, 2024 - Explains how to install GNU C, C++ compiler and other development tools on a CentOS and RHEL (Red Hat Enterprise Linux) version 7.x server/workstation.
🌐
Medium
bipulkkuri.medium.com › install-latest-gcc-on-centos-linux-release-7-6-a704a11d943d
Install latest GCC on Centos Linux release 7.6
August 18, 2020 - #!/bin/shGCC_VERSION=9.2.0 sudo yum -y update sudo yum -y install bzip2 wget gcc gcc-c++ gmp-devel mpfr-devel libmpc-devel make gcc --version wget http://gnu.mirror.constant.com/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.gz tar zxf gcc-$GCC_VERSION.tar.gz mkdir gcc-build cd gcc-build ../gcc-$GCC_VERSION/configure --enable-languages=c,c++ --disable-multilib make -j$(nproc) sudo make install gcc --version cd .. rm -rf gcc-build · or follow this article from Red Hat itself. www.softwarecollections.org · Gcc · Centos · 10 followers ·
Find elsewhere
🌐
CyberITHub
cyberithub.com › install-gcc-and-c-compiler
Easy Steps to Install GCC(C and C++ Compiler) on CentOS 7 | CyberITHub
January 18, 2020 - Download from Repository and install gcc tool using yum install gcc command.
🌐
Psychz
psychz.net › client › kb › en › how-to-install-the-gcc-compiler-in-centos-7.html
How to install the GCC compiler in CentOS 7? ...
March 17, 2019 - Note: You need to log in to your CentOS 7 VPS via SSH as user root ... GCC can be easily installed from the official CentOS repositories. Run the following command to install GCC on your server ...
Call   800-933-1517
Address   611 Wilshire Blvd #300, 90017, Los Angeles,
Top answer
1 of 6
233

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
2 of 6
78

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

Top answer
1 of 2
16

I've confirmed that you can upgrade gcc from the default version 4.8 on centOS 7.

First, we need to install "Software Collections" in order to access some of the community packages including gcc v7

  • sudo yum install -y centos-release-scl

Next, we want to install a developer toolset. Depending on your needs, you may want a different devtoolset. Here I'm targeting 7:

  • sudo yum install -y devtoolset-7

Finally, you'll want to change over to gcc 7 as your default, launch a new shell session with the scl tool:

  • scl enable devtoolset-7 bash
2 of 2
1

Enable the software collection in the answer is only effective in the current shell. The scl utility will create a "child-shell" that set the PATH variables properly, so that in the new child-shell, the enabled software collections will be firstly searched. These settings obviously only take effective temporarily in the current shell.

To make it permanently effective, add the command, source /opt/rh/devtoolset-7/enable to the user's profile (~/.bash_profile or ~/.bashrc for RHEL based OS, like CentOS 7). Then, start a new shell and you will have the right tools available.

After execute scl enable devtoolset-7 bash, you will need to execute exit twice to exit the opened shell window, which verifies that the scl command created a new shell instance as a child process. There might be side-effect with creating a child-shell, so do not put this command in the ~/.bashrc profile, otherwise it will repeatedly create child-shell (non-login shell) as each shell will load the profile, resulting in a endless recursive loop. Put it in ~/.bash_profile, it will be loaded for only once (for the login shell), but you will need to exit twice every time.

But for development purpose, scl enable devtoolset-7 bash would be preferred, as you can exit the created child-shell, and then switch between different versions of the same software.


More details about the GCC version in python terminal:

The version info of the built-in Python in CentOS 7:

[root@conda condabuilder]# python
Python 2.7.5 (default, Nov 16 2020, 22:23:17) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

The version info of the user installed (via conda) Python on a system even without higher version of GCC installed:

[root@conda condabuilder]# conda activate jupyter
(jupyter) [root@conda condabuilder]# python -VV
Python 3.10.9 | packaged by conda-forge | (main, Feb  2 2023, 20:20:04) [GCC 11.3.0]

From the results, we can see that the GCC version contained in Python's version info is not related to the system's GCC. The system's default Python (2.7.5) should have been compiled with the GCC version distributed with CentOS 7, so the version info show the same GCC version. But for user installed python, the GCC version info actually depends on what version of GCC is used for building and packging the python binary.

🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › hardware and peripherals › compute module
help : centos7.9 can't install gcc 10 - Raspberry Pi Forums
COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/armv7hl-redhat-linux-gnueabi/4.8.5/lto-wrapper Target: armv7hl-redhat-linux-gnueabi Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --en
🌐
GitHub
gist.github.com › nchaigne › ad06bc867f911a3c0d32939f1e930a11
Building GCC 9.2.0 on CentOS 7 · GitHub
This note describes how to build the latest GCC (9.2.0 as of October 2019) from sources on CentOS 7. This should be applicable as is on RHEL 7. For other Linux distributions, adapt as needed. While this is not overly complicated, building GCC takes quite some time. So you might want to plan to do something else while it builds... a coffee break just won't make it. Prerequisites are described here: https://gcc.gnu.org/install/prerequisites.html
🌐
Stack Exchange
unix.stackexchange.com › questions › 585244 › how-do-i-get-gcc-to-run-on-centos-7
How do I get gcc to run on CentOS 7? - Unix & Linux Stack Exchange
May 7, 2020 - Recent versions of CentOS 7 include dnf, and with that you can install build requirements simply with:
🌐
GitHub
gist.github.com › liuziangexit › 888c818a66409e9bbe835002f3c785c7
install gcc7 in centos · GitHub
install gcc7 in centos · Raw · gistfile1.txt · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters ·