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

Answer from Destroyica on Stack Exchange
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
🌐
Red Hat
access.redhat.com › documentation › en-us › red_hat_developer_toolset › 11 › html-single › user_guide › index
User Guide | Red Hat Developer Toolset | 11 | Red Hat Documentation
July 19, 2023 - When you are working on a project ... having to compile the entire project. To compile an object file on the command line,: scl enable devtoolset-11 'gcc -o object_file -c source_file'...
Discussions

centos7 - How to `scl enable devtoolset-8 bash` when login in? - Stack Overflow
In my centos7, I tried to put scl enable devtoolset-8 bash command to ~/.bashrc but When I login in, processes of scl enable devtoolset-8 bash are started again and again until the process number r... More on stackoverflow.com
🌐 stackoverflow.com
Scl enable devtoolset-7 bash on Rocky 9
I didn’t find scl or devtoolset-7 to install. How should I do? Thank you very much. More on forums.rockylinux.org
🌐 forums.rockylinux.org
16
0
March 9, 2023
scripting - Bash - how to run scl_devtool-9 and get the gcc --version output - Unix & Linux Stack Exchange
My bash script: #!/bin/bash scl enable devtoolset-9 bash gcc --version result: devtoolset-9 is now enabled on the system, but I don't have the gcc --version output. gcc 9.x.x is installed. At the More on unix.stackexchange.com
🌐 unix.stackexchange.com
November 30, 2021
Highest scored 'devtoolset' questions - Stack Overflow
Normally in Zsh (~/.zshrc) or Bash (~/.bashrc) you would add lines similar to: source /opt/rh/... ... I have an application program "Cprog" that requires GCC 4.9 and C++11's libstdc++.so. To fulfill this requirement on CentOS 6, I am using Red Hat's devtoolset-6. This lib is located at: $ scl ... More on stackoverflow.com
🌐 stackoverflow.com
July 6, 2023
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 360004312319-enable-scl-devtoolset
enable scl devtoolset – IDEs Support (IntelliJ Platform) | JetBrains
1. I moved all my configuring code from .bashrc to .profile because (I don't remember exactly when) sometimes .bashrc was not applied to the environment. so for now devtoolset in .profile · 2. the command is "source scl_source enable devtoolset-4" .
🌐
University of Edinburgh
computing.help.inf.ed.ac.uk › scl
Software Collections | Documentation
To activate the devtoolset you ... You can run any application or script you wish, it does not need to be a shell. The scl enable command is used to enable the specified software collection....
Find elsewhere
🌐
Ucsf
wynton.ucsf.edu › hpc › software › scl.html
Software Collections (SCL)
[alice@dev2 ~]$ scl list-collections gcc-toolset-10 gcc-toolset-11 gcc-toolset-12 gcc-toolset-13 gcc-toolset-14 gcc-toolset-9
🌐
Stack Overflow
stackoverflow.com › questions › tagged › devtoolset
Highest scored 'devtoolset' questions - Stack Overflow
July 6, 2023 - As recommanded by RH,when i want ... either scl enable devtoolset-2 '... ... I have a bash script that executes the command scl enable devtoolset-8 'echo -e "%__ld $(which ld)\n%__nm $(which nm)\n%__objcopy $(which objcopy)\n%__objdump $(which objdump)\n%__strip $(which ...
🌐
MTU Service Desk
servicedesk.mtu.edu › TDClient › 1801 › Portal › KB › ArticleDet
Linux Software Collections (scl) - Service Desk
May 2, 2018 - ... We suggest you use your preferred shell as the program you run, because it best simplifies usage of software collections transparently. We expect most people will want to use ‘$ scl enable devtoolset-6 bash’ for their work.
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_developer_toolset › 12 › html-single › user_guide › index
User Guide | Red Hat Developer Toolset | 12 | Red Hat Documentation
Consider the employee file from Example 11.1, “Using memstomp”. Run the strace utility on this executable file and trace only the mmap and munmap system calls: $ scl enable devtoolset-12 'strace -e mmap,munmap ./employee' mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, ...
🌐
Stack Overflow
stackoverflow.com › questions › 43880358 › scl-enable-not-setting-path-with-bash
software collections - 'scl enable' not setting PATH with bash - Stack Overflow
$ scl --list devtoolset-4 python27 rh-java-common rh-perl524 rh-python35 $ which python /usr/bin/python $ python --version Python 2.6.6 $ scl enable python27 bash $ which python /usr/bin/python $ python --version Python 2.6.6 $ cat ...
🌐
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
🌐
Posit Support
support.posit.co › hc › en-us › articles › 360006145413-RStudio-Workbench-RStudio-Server-Pro-with-devtoolset-enabled
Posit Workbench with devtoolset enabled – Posit Support
July 25, 2024 - cc1plus: error: unrecognized command ... devtoolset-9 · Execute: gcc --version · Enable devtoolset-10 with: source scl_source enable devtoolset-9 ·...