22

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.

Dominic Cleal
  • 3,205
  • 19
  • 22
paweloque
  • 18,466
  • 26
  • 80
  • 136

3 Answers3

24

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
ProGM
  • 6,949
  • 4
  • 33
  • 52
Robert Cohen
  • 264
  • 3
  • 2
  • 8
    Putting it to /etc/profile.d/ is [much better solution](http://developerblog.redhat.com/2014/03/19/permanently-enable-a-software-collection/). What if the person is not a bash user? – Tomas Tomecek Aug 14 '14 at 06:30
4

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)]
fatherlinux
  • 109
  • 2
  • It seems to break if script.py is renamed to a name containing a space, like "abc def.py" – mogul May 15 '14 at 12:37
0

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

Trevor Boyd Smith
  • 18,164
  • 32
  • 127
  • 177