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
However, software collections will ... etc.). The usual way to enable software collections for whole sessions is to run a new bash wrapped with "scl ......
🌐
Linux Man Pages
linux.die.net › man › 1 › scl
scl(1) - Linux man page
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.
🌐
Utk
help.eecs.utk.edu › knowledge-base › linux-topics › using-redhat-software-collections
Using Red Hat Software Collections [EECS IT Help]
By running scl enable <collection name> <shell> you can start a new shell where the software contained in the collection is now the default.
🌐
Princeton CS Guide
csguide.cs.princeton.edu › software › scl
Software Collections (SCL) | Department of Computer Science Computing Guide
$ scl enable devtoolset-3 bash $ gcc --version gcc (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6) Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions.
🌐
SysTutorials
systutorials.com › docs › linux › man › 1-scl
scl: Setup and run software from Software Collection environment - Linux Manuals (1)
<collection> will no longer be considered SCL. If the <collection> was installed locally, then the use of --force is needed.i ... run set of commands listed in my_command file in the environment with baz Software Collection enabled
🌐
ManKier
mankier.com › home › scl-utils
scl: Setup and run software from Software Collection environment | Man Page | Commands | scl-utils | ManKier
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 ...
Find elsewhere
🌐
Soton
linuxdesktops.soton.ac.uk › softwarecollections.html
Software collections (SCL) — Linux Desktops RHEL7 documentation
Once you have installed an SCL package you must first ‘enable’ its use and run a program with the package enabled.
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
🌐
Gitbook
uaf-rcs.gitbook.io › uaf-rcs-hpc-docs › third-party-software › using-software-collections-scl
Using Software Collections (SCL) | UAF-RCS HPC Documentation
March 28, 2020 - $ scl enable software_collection... 'command...' Or, alternatively, use the following: Copy · $ scl enable software_collection... -- command... Replace "software_collection" with a space-separated list of SCLs you want to use, and "command" ...
🌐
Georgia Tech
support.cc.gatech.edu › support-tools › howto › how-use-software-collections
How to Use Software Collections | Technology Services Organization
To run the Bash shell in the environment with multiple Software Collections enabled, execute the following command: scl enable software_collection_1 software_collection_2 bash
🌐
Ucsf
wynton.ucsf.edu › hpc › software › scl.html
Software Collections (SCL)
[alice@dev2 ~]$ scl enable gcc-toolset-12 "$SHELL" [alice@dev2 ~]$ gcc --version gcc (GCC) 12.2.1 20221121 (Red Hat 12.2.1-7) Copyright (C) 2022 Free Software Foundation, Inc. This is free software; see the source for copying conditions.
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.

🌐
Fedora Documentation
jfearn.fedorapeople.org › fdocs › en-US › Fedora_Contributor_Documentation › 1 › html › Software_Collections_Guide › sect-Enabling_Support_for_Software_Collections.html
1.3. Enabling Support for Software Collections
To enable support for Software Collections on your system so that you can enable and build Software Collections, you need to have installed the packages scl-utils and scl-utils-build.
Top answer
1 of 1
3

I'm not familiar with scl at all, but I can point out some things that're wrong with the shell part of what you're doing:

  • Use $ with variable to get their values, not when setting them. Therefore, $ARG=argument should be ARG=argument. BTW, the error message you gave doesn't actually match this problem; it looks more like what you'd get with spaces around the = (e.g. ARG = argument), which isn't allowed because it'll treat ARG as a command, and "=" and "argument" as arguments to pass to it. In general, spaces are important delimiters in the shell, and adding or removing them -- even in unimportant-looking places -- can completely change the meaning of a command.

  • By default, variables are private to the shell itself. To make the variable available to scl (and any other commands you run in the shell), you need to export it. Thus, you actually want:

    export ARG=argument
    
  • I recommend against using all-caps variable names, since there are a number of all-caps names that have special meanings; using one of those for something else can have weird effects. Lower- and mixed-case variable names are safer.

  • Inside a regular here-document (the part that << SS opens), the shell will expand $variable expressions before sending the document to the program. If you want that $ expression to be sent to the program for it to interpret, you need to either quote the here-doc delimiter (e.g. << "SS"), or backslash-escape all dollar-signs, backticks, and backslash characters in the document.

🌐
MTU Service Desk
servicedesk.mtu.edu › TDClient › 1801 › Portal › KB › ArticleDet
Linux Software Collections (scl) - Service Desk
May 2, 2018 - We expect most people will want to use ‘$ scl enable devtoolset-6 bash’ for their work. To modify your environment to always use a scl environment, add ‘source scl_source enable devtoolset-6’ to your ~/.bashrc .