On CentOS 6.4:

I installed a newer version of devtoolset (1.1) and was wondering how I would go about permanently setting these to be default. Right now, when I ssh into my server running CentOS 6, I have to run this command scl enable devtoolset-1.1 bash

I tried adding it to ~/.bashrc and simply pasting it on the very last line, without success.

5 Answers 5


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


source scl_source enable devtoolset-2

Lot more efficient: no forkbomb, no tricky shell

  • This was applicable on centos 6.8. Just a minor change to "source /opt/rh/devtoolset-3/enable"
    – JonnyRo
    Commented Jun 27, 2016 at 18:37
  • 2
    sourcing this file is still working with devtoolset-7
    – Dan D.
    Commented Aug 27, 2018 at 10:52
  • 1
    @datdinhquoc yes, you need to source /opt/rh/devtoolset-7/enable
    – Destroyica
    Commented Sep 7, 2018 at 17:32
  • 1
    Just a late note on this: scl scl_source enable gcc-toolset-11 doesn't work in zsh, only bash -- something about arrays I think. But source /opt/rh/gcc-toolset-11/enable works fine even in zsh.
    – GaryO
    Commented Oct 18, 2023 at 14:20
  • source /opt/rh/devtoolset-11/enable was my savior after I updated Centos7
    – rahman
    Commented Nov 28, 2023 at 11:42

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:

The scl_source installed on my Red Hat 7.1


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

Don't use this script outside of SCL scriptlets!

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

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

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

if [ -z "$_scl_dir" ]; then
    # No need to re-define the directory twice
    if [ ! -e $_scl_dir ]; then

for arg in "$@"; do
    _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

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

    # Now check if the collection isn't already enabled
    /usr/bin/scl_enabled $arg > /dev/null 2> /dev/null
    if [ $? -ne 0 ]; then

if [ $_recursion == "false" ]; then
    while [ $_i -lt ${#_scls[@]} ]; do
        source "$_scl_scriptlet_path"
        if [ $? -ne 0 ]; then
            echo "Can't source $_scl_scriptlet_name, skipping."
            export X_SCLS="${_scls[$_i]} $X_SCLS"

The problem is that scl enable devtoolset-1.1 bash creates a new bash shell. So when you put it in your .bashrc, it creates a new shell...which loads your .bashrc, which runs scl enable devtoolset-1.1 bash, which creates a new shell, which loads your .bashrc... Forkbomb!

You probably want something like this in your .bashrc:

if [ "$(gcc -dumpversion)" != "4.7.2" ]; then 
  scl enable devtoolset-1.1 bash


if [ -z "$TRIEDSCLDEVTOOLSET" ]; then
  scl enable devtoolset-1.1 bash
  • the first will continue to forkbomb if devtoolset-1.1 does not contain gcc 4.7.2, and will also fail to work if your native environment has gcc 4.7.2.
  • this creates a new shell, as above. So when you create your terminal window or ssh session, you will be in two bash sessions, and have to exit twice.
  • Thanks for taking the time to reply. I indeed got a fork bomb and didn't understand why but that makes perfect sense. It sounds like using scl enable devtoolset-1.1 bash is not the practical way to go then since I'm only going to be putting use to 4.7.2 and not the older version. Would I just need to remove the older version of devtools and do some other things to only have the one version?
    – SelfTaught
    Commented Dec 26, 2014 at 18:48
  • If you have root privileges on the machine and never need the older version of gcc (or of the other tools in devtoolset-1.1) then yes, you may want to just install the latest gcc natively. You don't have to remove devtoolset, just don't scl enable it.
    – rob05c
    Commented Dec 26, 2014 at 19:43
  • Gotcha. Yeah I've got root permissions. How do you "install" things natively? Both are installed but I have to run scl enable every time i open a new ssh session. I apologize for these noobish questions but I'm not sure how to go about setting the newer version as default. Is there an environment variable which I need to export in my bash profile?
    – SelfTaught
    Commented Dec 26, 2014 at 19:52
  • It sounds like you don't understand how scl and devtoolset work. Devtoolset is a collection for Software Collections (SCL). SCL lets you use multiple versions of the same tool. For example, if you need GCC 4.4 and GCC 4.7 on the same machine, you can do it with SCL. GCC 4.7 isn't really installed on your system, it's in the SCL environment. Only the older version (4.4?) is really installed. To install apps natively, use your distro's package manager. On Ubuntu, this is apt-get, e.g. sudo apt-get install gcc. On CentOS, this is yum, e.g. sudo yum install gcc.
    – rob05c
    Commented Dec 26, 2014 at 20:28
  • I suspect you have an old version of CentOS that doesn't have gcc4.7 in yum yet. I would do sudo yum update && sudo yum install gcc and check gcc --version. If it's not 4.7, then you probably have to use devtoolset. If you don't want to run it in SCL, you can uninstall the native gcc with sudo yum remove gcc and then add the devtoolset directory to your path, i.e. put export PATH=$PATH:/opt/centos/devtoolset-1.1/root/usr/bin in your .bashrc. That will let you type gcc or g++ and get the devtoolset gcc4.7.
    – rob05c
    Commented Dec 26, 2014 at 20:35

An alternate way to locate the script mentioned in other answers is to let your package manager tell you where it lives.

This is what we run to pull in the dotnet tools on our RHEL/CentOS vagrant machines.

source $(rpm -ql rh-dotnet20-runtime|grep -E /enable$)


For enabling it across systems for all users. Please make changes in "/etc/profile" as below:

source scl_source enable devtoolset-2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .