Simply use dnf
Copydnf -y install gcc-toolset-9-gcc gcc-toolset-9-gcc-c++
source /opt/rh/gcc-toolset-9/enable
ref: https://centos.pkgs.org/8/centos-appstream-x86_64/gcc-toolset-9-gcc-9.1.1-2.4.el8.x86_64.rpm.html
Note: source won't work inside a Dockerfile so prefer to use:
CopyENV PATH=/opt/rh/gcc-toolset-9/root/usr/bin:$PATH
or better
CopyRUN dnf -y install gcc-toolset-9-gcc gcc-toolset-9-gcc-c++
RUN echo "source /opt/rh/gcc-toolset-9/enable" >> /etc/bashrc
SHELL ["/bin/bash", "--login", "-c"]
RUN gcc --version
Answer from Mizux on Stack OverflowSimply use dnf
Copydnf -y install gcc-toolset-9-gcc gcc-toolset-9-gcc-c++
source /opt/rh/gcc-toolset-9/enable
ref: https://centos.pkgs.org/8/centos-appstream-x86_64/gcc-toolset-9-gcc-9.1.1-2.4.el8.x86_64.rpm.html
Note: source won't work inside a Dockerfile so prefer to use:
CopyENV PATH=/opt/rh/gcc-toolset-9/root/usr/bin:$PATH
or better
CopyRUN dnf -y install gcc-toolset-9-gcc gcc-toolset-9-gcc-c++
RUN echo "source /opt/rh/gcc-toolset-9/enable" >> /etc/bashrc
SHELL ["/bin/bash", "--login", "-c"]
RUN gcc --version
this command work for me
Copydnf install gcc --best --allowerasing
linux - Can not find required gcc version after devtoolset installation - Stack Overflow
Installing devtoolset-X
How to install devtoolset-11 on Centos 8 Stream - Stack Overflow
linux - How to install gcc8 using devtoolset-8-gcc - Stack Overflow
I am using CentOS 7.9 and I encountered the same problem after following instructions here to install and run gcc 11. I tried launching different versions of gcc and found only devtoolset-9 works, which corresponds to the file devtoolset-9 in /etc/scl/conf/ folder. So I copied devtoolset-9 to devtoolset-11 in the same folder, and gcc 11 gets working.
I ran into the same issue that you are facing and this is how I got it fixed:
- Just want to be careful, you need to exist the Terminal and open a fresh one to start. This way, you are not under any devtoolset's bash.
- Go to /opt/rh folder, run command ls -la to see if you have any devtoolset-* folder there. Let's say you have devtoolset-8, proceed step 2.
- Go to /etc/scl/prefixes folder, if you don't see devtoolset-8 file, you can create a new one as devtoolset-8, and type 1 line: /opt/rh, then save and quit that file.
- Once you are done, you can call: scl enable devtoolset-8 -- bash w/o any error. Good luck
On CentOS I can do yum install devtoolset-8 followed by scl enable devtoolset-8 bash so that my paths are setup to use GCC et al packaged with that development toolset.
Is there an equivalent in AlmaLinux?
To install the full tools-set including gfortran on centos 7:
yum install centos-release-scl
yum install devtoolset-8
scl enable devtoolset-8 -- bash
enable the tools:
source /opt/rh/devtoolset-8/enable
you may wish to put the command above in .bash_profile
ref: https://unix.stackexchange.com/questions/477360/centos-7-gcc-8-installation
devtoolset-8 was only released a short while ago. The linked installation instructions may be of use. However, your question pertains to CentOS, and this does not yet appear to have been made available yet. You can see some evidence of it being build for CentOS here, but it's not been updated for the final release yet.
You could ask on the SCL mailing list for an ETA, or wait until it appears in its final form. In the meantime, you could download the RPMs from koji directly.
What I have so far:
cat Dockerfile
FROM centos:7 AS env
RUN yum update -y
RUN yum install -y centos-release-scl
RUN yum install -y devtoolset-9
RUN echo "source /opt/rh/devtoolset-9/enable" >> /etc/bashrc
SHELL ["/bin/bash", "--login", "-c"]
RUN gcc --version
So you must:
Add the source stuff in a bashrc
note: On Centos it's/etc/bashrcwhile on ubuntu it's/etc/bash.bashrcUpdate the docker default shell to be bash AND to "load" the bashrc using
--login
Output
docker build .
Sending build context to Docker daemon 4.096kB
Step 1/32 : FROM centos:7 AS env
---> 8652b9f0cb4c
Step 2/32 : RUN yum update -y
---> Using cache
---> a2bb269cd8dc
Step 3/32 : RUN yum install -y centos-release-scl
---> Using cache
---> 1184e26c71cf
Step 4/32 : RUN yum install -y devtoolset-9
---> Using cache
---> e678665d2a4e
Step 5/32 : RUN echo "source /opt/rh/devtoolset-9/enable" >> /etc/bashrc
---> Using cache
---> fe1745d4ca87
Step 6/32 : SHELL ["/bin/bash", "--login", "-c"]
---> Running in 2dd7955f4487
Removing intermediate container 2dd7955f4487
---> 3cf4835bf680
Step 7/32 : RUN gcc --version
---> Running in b5de3266d607
gcc (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)
Copyright (C) 2019 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.
...
What won't work
Test 1
RUN scl enable devtoolset-9 bash
RUN gcc --version | head -1
each RUN is a new shell so the sub-bash is lost on the second line.
Test 2
RUN source /opt/rh/devtoolset-9/enable && gcc --version | head -1
RUN gcc --version | head -1
Here again the source is only for the first RUN shell command but will be lost...
Test 3
This may work but with potential unexpected behaviour
ENV PATH=/opt/rh/devtoolset-9/root/bin:$PATH
RUN gcc --version | head -1
here we only "fix" the PATH variable but if you look at the /opt/rh/devtoolset-9/enable script there is so more to do than only updating the PATH...
You may give it a try using the below steps if that may help: Download the latest package from http://ftp.gnu.org/gnu/gcc/gcc-9.2.0/
wget http://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gz
Extract the files using the steps below:
tar -xzvf gcc-9.20.tar.gz
cd gcc-9.2.0
Build a configuration using the below,
./configure
Compile the installation using make and then make install.
make
make install