Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Install gcc 5.3 with yum on CentOS 7.2?

I am using CentOS 7.2

When I use yum groupinstall "Development Tools", gcc version is 4.8.5, like this:

enter image description here

I would like to install gcc 5.3

How to approach this with yum?

like image 350
sunshine Avatar asked Mar 31 '16 08:03

sunshine


People also ask

What is the version of GCC on CentOS 7?

CentOS 7 distribution (as well as RHEL 7) ships with a somewhat outdated version of the GCC compiler (4.8. 5 on CentOS 7.5), which may not be suitable to your compilation requirements. For example, C11 - which supersedes C99 - is fully supported only starting from GCC 4.9).

Does CentOS come with GCC?

The default CentOS repositories contain a package group named Development Tools that contains the GCC compiler and a lot of libraries and other utilities required for compiling software.


2 Answers

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 
like image 82
tesch1 Avatar answered Nov 10 '22 12:11

tesch1


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

enter image description here enter image description here

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:

enter image description here

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

like image 27
HDJEMAI Avatar answered Nov 10 '22 12:11

HDJEMAI