How to Install gcc 5.3 with yum on CentOS 7.2?

2019-01-12 16:51发布

问题:

I am using CentOS 7.2

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

I would like to install gcc 5.3

How to approach this with yum?

回答1:

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:

Update: 15 December 2018:

Installing latest major version of gcc: gcc 8 (GCC 8.2.0) - released 07/26/2018:

GCC 8.2 is a bug-fix release for gcc 8.1.0, containing substantial new functionality not available in GCC 7.x or previous GCC releases.

Download file: https://ftp.gnu.org/gnu/gcc/gcc-8.2.0/gcc-8.2.0.tar.gz

Compile and install:

//required libraries:
yum install libmpc-devel mpfr-devel gmp-devel

yum install zlib-devel*

./configure --with-system-zlib --disable-multilib --enable-languages=c,c++

make -j 8 <== this may take around 75 minutes or less to finish with 8 threads
              (depending on your cpu speed)

make install

Result: gcc 8.2.0 and g++ 8.2.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:

Old answer:

Right now, there is no rpm package in order to install gcc 5.3 with yum in CentOS 7.2 or even CentOS 7.3

The solution is to install gcc 5.3 from source code:

1: Intstall the required libs

sudo yum install libmpc-devel mpfr-devel gmp-devel

Accept to install the CentOS GPG Key in this step

Install - zlib

yum install zlib-devel*

2: Download the required source and install

curl ftp://ftp.gnu.org/pub/gnu/gcc/gcc-5.3.0/gcc-5.3.0.tar.bz2 -O

//If you want to verify the downloaded file, use this sig file: 
ftp://ftp.gnu.org/pub/gnu/gcc/gcc-5.3.0/gcc-5.3.0.tar.bz2.sig

tar xvfj gcc-5.3.0.tar.bz2

cd gcc-5.3.0

//here you can add other languages you want to be supported for your gcc like Java or Go,...
./configure --with-system-zlib --disable-multilib --enable-languages=c,c++

// 4 = number of independent central processing units (# of Cores)
make -j 4

make install

Verify the version:

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



回答3:

The best approach to use yum and update your devtoolset is to utilize the CentOS SCLo RH Testing repository.

yum install centos-release-scl-rh
yum --enablerepo=centos-sclo-rh-testing install devtoolset-7-gcc devtoolset-7-gcc-c++

Many additional packages are also available, to see them all

yum --enablerepo=centos-sclo-rh-testing list devtoolset-7*

You can use this method to install any dev tool version, just swap the 7 for your desired version. devtoolset-6-gcc, devtoolset-5-gcc etc.



回答4:

You can use the centos-sclo-rh-testing repo to install GCC v7 without having to compile it forever, also enable V7 by default and let you switch between different versions if required.

sudo yum install -y yum-utils centos-release-scl;
sudo yum -y --enablerepo=centos-sclo-rh-testing install devtoolset-7-gcc;
echo "source /opt/rh/devtoolset-7/enable" | sudo tee -a /etc/profile;
source /opt/rh/devtoolset-7/enable;
gcc --version;


回答5:

Command to install GCC and Development Tools on a CentOS / RHEL 7 server

Type the following yum command as root user:

yum group install "Development Tools"

OR

sudo yum group install "Development Tools"

If above command failed, try:

yum groupinstall "Development Tools"