首页 > 解决方案 > 如何在docker centos7中安装gcc7

问题描述

我正在尝试基于centos7

FROM centos:centos7

RUN yum -y update
RUN yum -y install gcc
RUN gcc --version

安装gcc的是4.8:

 4/4 : RUN gcc --version
 ---> Running in 70b9aa4a1f67
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
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.

如何安装 gcc7?我试过 devtools-7,它不起作用:

FROM centos:centos7

RUN yum -y update
RUN yum -y install scl-utils
RUN yum -y install devtoolset-7-gcc
RUN scl enable devtoolset-7 bash
RUN gcc --version

我有:

Step 4/6 : RUN yum -y install devtoolset-7-gcc
 ---> Running in 85b49f411d4c
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: mirror.imt-systems.com
 * extras: mirror.23media.com
 * updates: ftp.plusline.net
No package devtoolset-7-gcc available.
Error: Nothing to do
The command '/bin/sh -c yum -y install devtoolset-7-gcc' returned a non-zero code: 1

标签: dockergcccentos7

解决方案


Dockerfile 中的以下命令对我有用:

RUN yum install -y centos-release-scl
RUN yum install -y devtoolset-7-gcc-*
RUN echo "source scl_source enable devtoolset-7" >> /etc/bashrc
RUN source /etc/bashrc

推荐阅读