问题
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: Installing latest version of gcc 9: (gcc 9.2.0) - released August 12, 2019:
Download file: https://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.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 70 minutes or less to finish with 8 threads
(depending on your cpu speed)
make install
Result: gcc 9.2.0 and g++ 9.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:
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"
来源:https://stackoverflow.com/questions/36327805/how-to-install-gcc-5-3-with-yum-on-centos-7-2