Solve it by using echo "source /opt/rh/devtoolset-8/enable" >> /etc/profile

Answer from GOGO on Stack Overflow
Discussions

linux - How to permanently enable newer version of software installed from SCL repo? - Unix & Linux Stack Exchange
Right now, when I ssh into my server ... command scl enable devtoolset-1.1 bash · I tried adding it to ~/.bashrc and simply pasting it on the very last line, without success. ... In your ~/.bashrc or ~/.bash_profile Simply source the "enable" script provided with the devtoolset. For example, with the Devtoolset 2, the command is: ... This was applicable on centos 6.8... More on unix.stackexchange.com
🌐 unix.stackexchange.com
May 8, 2020
Solved: Bamboo how to set scl enable with docker environme...
Hello :) I am having a hard time to change GCC version on centos image. I use Docker image to build on a centos environment. I made my base image and I tried to use the image. I already set the "scl" command for my base image. I also gave these two commands inside of my Dockerfile. SHELL [... More on community.atlassian.com
🌐 community.atlassian.com
October 10, 2019
Installing devtoolset-X
$ sudo dnf search toolset Last metadata expiration check: 2:26:13 ago on Mon 15 Nov 2021 05:10:30 AM EST. ============================================= Name & Summary Matched: toolset ==== gcc-toolset-10.x86_64 : Package that installs gcc-toolset-10 gcc-toolset-10-runtime.x86_64 : Package that handles gcc-toolset-10 Software Collection. gcc-toolset-11.x86_64 : Package that installs gcc-toolset-11 gcc-toolset-11-runtime.x86_64 : Package that handles gcc-toolset-11 Software Collection. gcc-toolset-9.x86_64 : Package that installs gcc-toolset-9 gcc-toolset-9-runtime.x86_64 : Package that handles gcc-toolset-9 Software Collection. So do dnf-install gcc-toolset-X, then scl enable devtoolset-X bash More on reddit.com
🌐 r/AlmaLinux
1
7
November 14, 2021
centos7 - Enable devtoolset-8 for zsh on Centos 7 - Stack Overflow
I run Centos 7, and I installed devtoolset-8 in order to get gcc 8. Here I found how to enable it for bash, which is done simply by adding source scl_source enable devtoolset-8 to .bashrc. If I ap... More on stackoverflow.com
🌐 stackoverflow.com
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 360004312319-enable-scl-devtoolset
enable scl devtoolset – IDEs Support (IntelliJ Platform) | JetBrains
When you do scl enable devtoolset, it is simply pointing towards what devtoolset provides. ... And you will see that the g++ version has changed after enabling devtoolset. ... actually just a replacing the paths of the toolchain with a specific for devtoolset, seems doesn't work for me in all cases, something with link paths · anyway an applying that is a more correct way, isn't it? so bashrc script on remote host applies this to work properly, so default configured toolchain replaced on the compilation.
Top answer
1 of 5
93

In your ~/.bashrc or ~/.bash_profile Simply source the "enable" script provided with the devtoolset. For example, with the Devtoolset 2, the command is:

source /opt/rh/devtoolset-2/enable

or

source scl_source enable devtoolset-2

Lot more efficient: no forkbomb, no tricky shell

2 of 5
17

An alternative of source /opt/rh/devtoolset-4/enable is

source scl_source enable devtoolset-4

The above shell script scl_source is more elegant than using a hard coded path (may be different on another machine). However scl_source does less because /opt/rh/devtoolset-4/enable uses scl_source and other stuff.

To use scl_source you may have to upgrade package scl-utils

yum update scl-utils  # old scl-utils versions miss scl_source

Quick copy-paste

echo 'source scl_source enable devtoolset-4' >> ~/.bashrc
    # Do not forget to change the version ↑

Source code for curious people

An example of scl_source source code:
https://gist.github.com/bkabrda/6435016

The scl_source installed on my Red Hat 7.1

#!/bin/bash

_scl_source_help="Usage: source scl_source <action> [<collection> ...]

Don't use this script outside of SCL scriptlets!

Options:
    -h, --help    display this help and exit"

if [ $# -eq 0 -o $1 = "-h" -o $1 = "--help" ]; then
    echo "$_scl_source_help"
    return 0
fi


if [ -z "$_recursion" ]; then
    _recursion="false"
fi
if [ -z "$_scl_scriptlet_name" ]; then
    # The only allowed action in the case of recursion is the same
    # as was the original
    _scl_scriptlet_name=$1
fi
shift 1

if [ -z "$_scl_dir" ]; then
    # No need to re-define the directory twice
    _scl_dir=/etc/scl/conf
    if [ ! -e $_scl_dir ]; then
        _scl_dir=/etc/scl/prefixes
    fi
fi

for arg in "$@"; do
    _scl_prefix_file=$_scl_dir/$arg
    _scl_prefix=`cat $_scl_prefix_file 2> /dev/null`
    if [ $? -ne 0 ]; then
        echo "Can't read $_scl_prefix_file, $arg is probably not installed."
        return 1
    fi

    # First check if the collection is already in the list
    # of collections to be enabled
    for scl in ${_scls[@]}; do
        if [ scl ]; then
            continue 2
        fi
    done

    # Now check if the collection isn't already enabled
    /usr/bin/scl_enabled $arg > /dev/null 2> /dev/null
    if [ $? -ne 0 ]; then
        _scls+=($arg)
        _scl_prefixes+=($_scl_prefix)
    fi;
done

if [ $_recursion == "false" ]; then
    _i=0
    _recursion="true"
    while [ {#_scls[@]} ]; do
        _scl_scriptlet_path="${_scl_prefixes[$_i]}/${_scls[$_i]}/${_scl_scriptlet_name}"
        source "$_scl_scriptlet_path"
        if [ $? -ne 0 ]; then
            echo "Can't source $_scl_scriptlet_name, skipping."
        else
            export X_SCLS="${_scls[$_i]} $X_SCLS"
        fi;
        _i=_i+1))
    done
    _scls=()
    _scl_prefixes=()
    _scl_scriptlet_name=""
    _recursion="false"
fi
Find elsewhere
🌐
Softwarecollections
softwarecollections.org › en › scls › rhscl › devtoolset-8
Developer Toolset 8 — Software Collections
Install the collection: $ sudo yum install devtoolset-8 # 3. Start using software collections: $ scl enable devtoolset-8 bash
🌐
Stack Overflow
stackoverflow.com › questions › 43880358 › scl-enable-not-setting-path-with-bash
software collections - 'scl enable' not setting PATH with bash - Stack Overflow
I originally checked ~/.bash* files as well as /etc/bash* and /etc/profile but after your comment, I found several scripts in /etc/profile.d/ that we being executed, and one of them set the PATH explicitly without appending. I added $PATH back in there and now scl enable is working as expected!
🌐
University of Edinburgh
computing.help.inf.ed.ac.uk › scl
Software Collections | Documentation
As with the devtoolset the llvm-toolset packages are installed in an alternate location so that they can exist on a system alongside the standard versions. This means they are not in the standard path. To activate this collection you need to do something like this: ... One way would be to alias the software, but 'scl enable' uses the shell positional parameters in such a way that an alias confuses things - it looks in the "wrong" place for the name of the software collection.
🌐
Copperspice
forum.copperspice.com › board index › installation
Support for RHEL? - CopperSpice Forum
There is an official way to install new gcc on rhel/centos, that will not disrupt original gcc that comes with the distribution. sudo yum install centos-release-scl-rh sudo yum install devtoolset-8-gcc-c++ and then run: scl enable devtoolset-8 bash This will run new bash session with a brand new gcc with the support of c++17 you can make it permanent system-wide, just create etc/profile.d/enable_devtoolset.sh #!/bin/bash source scl_source enable devtoolset-8 and reboot The way it works is that linking process will take all the symbols provided by original libstdc++ provided by the distro, and then link in statically missing parts that comes with new compiler.
🌐
Stack Overflow
stackoverflow.com › questions › tagged › devtoolset
Newest 'devtoolset' Questions - Stack Overflow
I was trying to install devtoolset-8 in my slave node with no active internet connection running centos7. I am using all .rpm packages required as dependencies. During installation through rpm -ivh * ... ... I am trying to install graph-tool on a RHEL7 within a virtual environment; it uses both, Python 3 and gcc 7 or above. I am unable to use both of them within the same scl bash shell.
🌐
Red Hat
bugzilla.redhat.com › show_bug.cgi
1319936 – sudo is broken after installing devtoolset
Red Hat Bugzilla – Bug 1319936 · This site requires JavaScript to be enabled to function correctly, please enable it · Privacy Contact FAQ Legal
🌐
GitHub
github.com › Websoft9Archive › role_redis › issues › 8
scl enable devtoolset-7 llvm-toolset-7 bash waiting for long time in the task Install GCC for Redis6.0 · Issue #8 · Websoft9Archive/role_redis
December 19, 2020 - name: Install GCC for Redis6.0, refer to GCC 4.8 vs C11 _Atomic and threaded IO redis/redis#7509 shell: | sudo yum -y install centos-release-scl devtoolset-7 llvm-toolset-7 scl enable devtoolset-7 llvm-toolset-7 bash when: redis_version == "6.0"
Author   Websoft9Archive
Top answer
1 of 1
1

Copying comments into the semblance of an answer.

Change the sh script_1.sh etc lines to bash -x script_1.sh (or sh -x script_1.sh since the scripts don't seem to use any Bash-specific syntax) and monitor what's going on. Do you see the version information from gcc --version in script_1.sh?

gcc --version is only printed when I comment out scl enable devtoolset-9 bash. I ran scl enable devtoolset-9 bash and it does not output anything to the screen.

That suggests the scl command is not completing. Maybe it is waiting for input from the terminal. Do you see the output from which gcc when you include the scl command? If not, then it is close to certain that scl is trying to read from the terminal. I dunno what it's reading — it isn't a command I'm familiar with.

It is not waiting for any input. After execution, it brings the prompt again when I run it by itself.

If you're not seeing the which gcc and gcc --version output, then it is probable that the scl command is not completing, IMO. What does the bash at the end of the command options do? Does it run a bash process? If so, where is its input coming from? Running with the -x option (sh -x script_1.sh) would show you what is being executed, and whether scl is completing.

scl enable foo bar bash actually runs a bash instance with foo and bar Software Collections enabled. See https://linux.die.net/man/1/scl

OK; and what is that bash instance doing? Is it not waiting for input before it executes anything? It's a little surprising that there isn't a prompt, but not completely astonishing. Have you tried typing exit when scl hangs?

I just tried scl enable devtoolset-9 bash & echo "Enabling devtoolset-9" and it works and ultimately prints out the gcc --version.

Well, that & runs the scl command in background, leaving the echo to run, and then which gcc and gcc --version. Replace the & with a semicolon. Or replace the & with -c 'echo Hi' and a semicolon and see what happens.

Wonderful! Adding -c echo "Hi" made it work!

So that bash command specified at the end of scl enable devtoolset-9 bash was waiting for input from you, which is why it didn't terminate (and you don't see which gcc running) and so on. You've got the same issue at the end of script_2.sh — what about the other scripts? But you now know what's going on and can decide what to do about it. Using -c exit would simply terminate the shell (instead of echoing Hi), for example.

I'd need to study the scl command more, but do you actually need to use it in these scripts?

🌐
LinuxQuestions.org
linuxquestions.org › questions › red-hat-31 › make-not-using-developer-set-version-of-gcc-in-bash-4175615807
[SOLVED] make not using developer-set version of gcc in bash
October 17, 2017 - Hi! Code: [idae@rh69bdb scripts] cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.9 (Santiago) With this version, it's gcc 4.4