Permanently enable RHEL scl

15.2k views Asked by At

Is there a way to permanently enable custom Software Collections for RedHat?

I have installed an scl to provide python27 in RHEL6 and don't want to have to enable the custom scl every time.

3

There are 3 answers

1
Robert Cohen On BEST ANSWER

Well, you could add something to your startup script to source the enable script.

Eg add to your .bash_profile (note space between initial dot and /)

. /opt/rh/python27/enable
0
Trevor Boyd Smith On

In a nutshell: source scl_source enable name

  • to find the name you can do scl --list



longer story:

In your ~/.bashrc or ~/.bash_profile or /etc/profile.d/enable_name.sh

if command -v scl_source &>/dev/null; then
    source scl_source enable name
fi

Hat tip to:

p.s. do not use any solution that spawns a new shell because it can Forkbomb you and prevent you from being able to login

  • for more information on avoiding the ForkBomb read here1 and here2

p.s. SCL goes away in EnterpriseLinux version >= el8

1
fatherlinux On

This option sounds dangerous to me for root. I would think something like the following would be safer and more appropriate:

You can create a function that takes command line options. Think of this as an alias on steroids. Add the following to your .bashrc

python27() {
scl enable python27 “python $*”
}

Then test:

python27 –version
Python 2.7.5

This doesn’t help with your magic line in scripts, but will make it easier to call scripts:

[smccarty@keith ~]$ cat script.py
#!/usr/bin/env python27

import sys

print “Hello, World!”, sys.version

Call it normal and notice, the default installation of python is used:

[smccarty@keith ~]$ ./script.py
Hello, World! 2.6.6 (r266:84292, Sep 4 2013, 07:46:00)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)]

Call it with our alias, and notice that Python 2.7 is used:

[smccarty@keith ~]$ python27 script.py
Hello, World! 2.7.5 (default, May 23 2013, 06:08:09)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)]