using scl enable actually opens a new shell inside your current one, which is quite unclean, especially if done from a login script.

You should place, instead, in your ~/.bash_profile:

source /opt/rh/rh-nginx18/enable

or:

source scl_source enable rh-nginx18

The latter is more "elegant" as it is independent from the actual installation path.

This has the effect of loading the environment in your current shell.

Answer from l3g3nd4ryf0x on serverfault.com
🌐
Red Hat
access.redhat.com › solutions › 527703
How can I make a Red Hat Software Collection persist after a reboot/logout? - Red Hat Customer Portal
The tricky part comes when you realize, that pure running "scl enable ..." in /etc/profile.d/something.sh doesn't work, because you cannot influence environment of the parent's process.
🌐
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!
Discussions

cron - scl enable python27 bash - Stack Overflow
You can do this from within a bash ... environment, of the SCL package, which is located at /opt/rh/python27/enable ... #!/bin/bash cd /var/www/python/scripts/ source /opt/rh/python27/enable python runAllUpserts.py >/dev/null 2>&1 ... This works well in my experience - only ... More on stackoverflow.com
🌐 stackoverflow.com
Solved: Bamboo how to set scl enable with docker environme...
ENV BASH_ENV=/opt/app-root/etc/scl_enable \ ENV=/opt/app-root/etc/scl_enable \ PROMPT_COMMAND=". /opt/rh/devtoolset-8/enable" So, when I ran container from the image, it works well (I checked both bash and sh ). But bamboo seems not to use my base image and cannot compile source code because ... More on community.atlassian.com
🌐 community.atlassian.com
October 10, 2019
python 2.7 - How to use scl command as a script shebang? - Stack Overflow
No matter what, argument splitting based on quote sis not supported. So when you write: ... And that would fail since it wont be able to find a command named enable python27 "ls /tmp" for scl to execute. There's a few workarounds you can use. More on stackoverflow.com
🌐 stackoverflow.com
linux - How to permanently enable newer version of software installed from SCL repo? - Unix & Linux Stack Exchange
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? ... It sounds like you don't understand how scl and devtoolset work... More on unix.stackexchange.com
🌐 unix.stackexchange.com
December 25, 2014
🌐
Red Hat
bugzilla.redhat.com › show_bug.cgi
1016962 – scl enable does not set up the environment in a nested invocation
October 16, 2013 - Red Hat Bugzilla – Bug 1016962 · This site requires JavaScript to be enabled to function correctly, please enable it · Privacy Contact FAQ Legal
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_software_collections › 3 › html › packaging_guide › sect-enabling_the_software_collection
1.6. Enabling a Software Collection | Packaging Guide | Red Hat Software Collections | 3 | Red Hat Documentation
You have to disable an enabled Software Collection first to be able to enable it again. To disable the Software Collection, exit the subshell created when enabling the Software Collections. When using the scl tool to enable a Software Collection, you can only perform one action with the enabled ...
Find elsewhere
🌐
Austindewey
austindewey.com › 2019 › 03 › 26 › enabling-software-collections-binaries-on-a-docker-image
Enabling Software Collections Binaries On A Docker Image<!-- --> - Austin Dewey
With the given Dockerfile, you could, however, run docker run –name scl-test -it scl-test to start an interactive /bin/sh session (leveraging ENV), and your scl binaries would be enabled there. Hopefully this helps resolve some confusion around Software Collections and persistently enabling scl binaries in a Dockerfile.
🌐
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 ... was not applied to the environment. so for now devtoolset in .profile · 2. the command is "source scl_source enable devtoolset-4" . here "4" constant depends which devtoolset you need, 4 refers to GCC531 for me ... Worked like a charm, ...
Top answer
1 of 3
3

You should try using -- instead of surrounding your command with quotes.

scl enable python27 -- ls /tmp

I was able to make a python script that uses the rh-python35 collection with this shebang:

#!/usr/bin/scl enable rh-python35 -- python

import sys
print(sys.version)
2 of 3
1

The parsing of arguments in the she-bang command is not really defined. From man execve:

The semantics of the optional-arg argument of an interpreter script vary across implementations. On Linux, the entire string following the interpreter name is passed as a single argument to the interpreter, and this string can include white space. However, behavior differs on some other systems. Some systems use the first white space to terminate optional-arg. On some systems, an interpreter script can have multiple arguments, and white spaces in optional-arg are used to delimit the arguments.

No matter what, argument splitting based on quote sis not supported. So when you write:

#!/usr/bin/scl enable python27 "ls /tmp"

It's very possible that what gets invoked is (using bash notation):

'/usr/bin/scl' 'enable' 'python27' '"ls' '/tmp"'

This is probably why it tries to open the "ls file at /etc/scl/prefixes/"ls

But it is just as likely that the shebang evaluates to:

'/usr/bin/scl' 'enable python27 "ls /tmp"'

And that would fail since it wont be able to find a command named enable python27 "ls /tmp" for scl to execute.

There's a few workarounds you can use.

You can call your script via scl:

$ cat myscript
#!/bin/bash
echo hello

$ scl enable python27 ./myscript
hello

You can also use the heredoc notation, but it might lead to subtle issues. I personally avoid this:

$ cat ./myscript
#!/bin/bash
scl enable python27 -- <<EOF
echo hi
echo \$X_SCLS
EOF

$ bash -x myscript 
+ scl enable python27 --
hi
python27

You can see one of the gotcha's already: I had to write \$X_SCLS to access the environment variable instead of just $X_SCL.

Edit: Another option is two have two scripts. One that has the actual code, and the second that simply does scl enable python27 $FIRST_SCRIPT. Then you wont have to remember to enter scl ... manually.

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 [ $arg == $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 [ $_i -lt ${#_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
Top answer
1 of 2
9

Use the scl_source feature.

Create a new file in /etc/profile.d/ to enable your collection automatically on start up:

$ cat /etc/profile.d/enablepython35.sh
#!/bin/bash
source scl_source enable python35

See How can I make a Red Hat Software Collection persist after a reboot/logout? for background and details.

2 of 2
1

This answer would be helpful to those who have limited auth access on the server.

I had a similar problem for python3.5 in HostGator's shared hosting. Python3.5 had to be enabled every single damn time after login. Here are my 10 steps for the resolution:

  1. Enable the python through scl script python_enable_3.5 or scl enable rh-python35 bash.

  2. Verify that it's enabled by executing python3.5 --version. This should give you your python version.

  3. Execute which python3.5 to get its path. In my case, it was /opt/rh/rh-python35/root/usr/bin/python3.5. You can use this path to get the version again (just to verify that this path is working for you.)

  4. Awesome, now please exit out of the current shell of scl.

  5. Now, lets get the version again through this complete python3.5 path /opt/rh/rh-python35/root/usr/bin/python3.5 --version.

    It won't give you the version but an error. In my case, it was

/opt/rh/rh-python35/root/usr/bin/python3.5: error while loading shared libraries: libpython3.5m.so.rh-python35-1.0: cannot open shared object file: No such file or directory
  1. As mentioned in Tamas' answer, we gotta find that so file. locate doesn't work in shared hosting and you can't install that too.

    Use the following command to find where that file is located:

find /opt/rh/rh-python35 -name "libpython3.5m.so.rh-python35-1.0"
  1. Above command would print the complete path (second line) of the file once located. In my case, output was
find: `/opt/rh/rh-python35/root/root': Permission denied
/opt/rh/rh-python35/root/usr/lib64/libpython3.5m.so.rh-python35-1.0
  1. Here is the complete command for the python3.5 to work in such shared hosting which would give the version,
LD_LIBRARY_PATH=/opt/rh/rh-python35/root/usr/lib64 /opt/rh/rh-python35/root/usr/bin/python3.5 --version
  1. Finally, for shorthand, append the following alias in your ~/.bashrc
alias python351='LD_LIBRARY_PATH=/opt/rh/rh-python35/root/usr/lib64 /opt/rh/rh-python35/root/usr/bin/python3.5'
  1. For verification, reload the .bashrc by source ~/.bashrc and execute python351 --version.

Well, there you go, now whenever you login again, you have got python351 to welcome you.

This is not just limited to python3.5, but can be helpful in case of other scl installed softwares.

🌐
University of Edinburgh
computing.help.inf.ed.ac.uk › scl
Software Collections | Documentation
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 ...
🌐
Linux Man Pages
linux.die.net › man › 1 › scl
scl(1) - Linux man page
scl utility allows to execute an application which is not located in the filesystem root hierarchy but is present in an alternative location. This application can still use and benefit from software installed in the root filesystem. In order to let an application be visible to the system one has to use scl utility as an interface. <action> is a script name to execute in a bash environment before the application itself takes in executed. Currently only enable scriptlet is mandatory which is needed to update search paths, etc.
🌐
Red Hat
access.redhat.com › discussions › 3279251
Red Hat Customer Portal - Access to 24x7 support and knowledge
January 4, 2018 - When executing scl command remote from other server cause error. Example ssh user1@server1.com scl enable rh-python36 'python /home/user1/setup.py install --user' cause error : Unable to open /etc/scl/conf/python!
🌐
GitHub
github.com › sclorg › s2i-python-container › issues › 88
Mechanism for enabling SCL packages. · Issue #88 · sclorg/s2i-python-container
January 11, 2016 - Currently the enabling of software collection packages is triggered by virtue of the following in sti-base. ... # IMPORTANT: Do not add more content to this file unless you know what you are # doing. This file is sourced everytime the shell session is opened. # This will make scl collection binaries work ...
Author   sclorg
🌐
Soton
linuxdesktops.soton.ac.uk › softwarecollections.html
Software collections (SCL) — Linux Desktops RHEL7 documentation
Typically the SCL packages will ... but not all do. Once you have installed an SCL package you must first ‘enable’ its use and run a program with the package enabled. For example: ... This ‘enables’ the rh-python35 package (Python 3.5) and then runs the command bash. The bash command is started with some environment variables changed so that the SCL software is then available, in a similar way to how Environment modules system work...