如何在CentOS 7.2上安装带有yum的gcc 5.3?

问题描述 投票:74回答:5

我使用的是CentOS 7.2

当我使用yum groupinstall "Development Tools"时,gcc版本是4.8.5,如下所示:

enter image description here

我想安装gcc 5.3

如何用yum解决这个问题?

gcc install centos7 yum gcc5
5个回答
143
投票

更新: 通常人们想要最新版本的gcc,并且devtoolset保持最新,所以也许你想要devtoolset-N,其中N = {4,5,6,7 ...},检查yum是否有最新版本在你的系统上)。更新了下面的cmds,N = 7。

作为示例,有一个用于devtoolset-7的gcc-7.2.1包。首先你需要启用Software Collections,然后它在devtoolset-7中可用:

sudo yum install centos-release-scl
sudo yum install devtoolset-7-gcc*
scl enable devtoolset-7 bash
which gcc
gcc --version

68
投票

更新:安装最新版本的gcc 9:(gcc 9.2.0) - 发布于2019年8月12日:

下载文件:https://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gz

编译并安装:

//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

结果:gcc 9.2.0和g ++ 9.2.0

enter image description here

安装gcc 7.4 (gcc 7.4.0) - 2018年12月6日发布:

下载文件:https://ftp.gnu.org/gnu/gcc/gcc-7.4.0/gcc-7.4.0.tar.gz

编译并安装:

//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

结果:

enter image description here

笔记:

1. This Stack Overflow answer将帮助您了解如何验证下载的源文件。

2.使用选项--prefix将gcc安装到默认目录以外的其他目录。顶级安装目录默认为/ usr / local。 Read about gcc installation options


5
投票

使用yum和更新devtoolset的最佳方法是使用CentOS SCLo RH测试存储库。

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

还有许多其他软件包可供查看

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

您可以使用此方法安装任何开发工具版本,只需将7替换为所需版本。 devtoolset-6-gcc,devtoolset-5-gcc等


2
投票

您可以使用centos-sclo-rh-testing repo来安装GCC v7而无需永久编译它,默认情况下也启用V7并允许您在不同版本之间切换(如果需要)。

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;

-10
投票

在CentOS / RHEL 7服务器上安装GCC和开发工具的命令

以root用户身份键入以下yum命令:

yum group install "Development Tools"

要么

sudo yum group install "Development Tools"

如果上面的命令失败,请尝试:

yum groupinstall "Development Tools"

© www.soinside.com 2019 - 2024. All rights reserved.