One of the students asked me about installing python2.7 on a redhat 6 system. Since I know the operating system depends on a particular version of python, I was immediately thinking about just upgrading the system to RHEL7, which would have the version of python required. But, happily, I’ve found that RedHat has provided a way to upgrade important systems. It has created a new channel called “RedHat Software Collections”. The beauty of these is that you can still use the regular package manager and that they won’t overwrite or conflict with system files. You need to enable the channel and install “scl-utils and scl-utils-build”. Then, the command to switch/see collections is scl. As an example,

[~]$ scl -l

Here’s an example of how it works.

[~]$ python -V
Python 2.6.6
[~]$ scl enable python27 bash
[~]$ python -V
python: error while loading shared libraries: cannot open shared object file: No such file or directory
[~]$ printenv LD_LIBRARY_PATH
[~]$ export LD_LIBRARY_PATH=/opt/rh/python27/root/usr/lib64:${LD_LIBRARY_PATH}
[~]$ python -V
Python 2.7.8
[~]$ exit
[~]$ python -V
Python 2.6.6

When you first login to the system, you have the standard python installation of 2.6.6. Then, after you enable the python27 package, you get an error. For some reason, the script that sets things up isn’t setting LD_LIBRARY_PATH correctly. Above I set it manually. Then, you can see the newer version of python. The scl program actually opens a new shell with a new path. So after entering ‘exit’ to leave that shell, you’re back to how things were originally.

My first problem is, why isn’t LD_LIBRARY_PATH being set correctly? The scl program is just sourcing the file /opt/rh/python27/enable. Here are the contents of that file.

[python27]$ cat enable
export PATH=/opt/rh/python27/root/usr/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/opt/rh/python27/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export MANPATH=/opt/rh/python27/root/usr/share/man:${MANPATH}
# For systemtap
export XDG_DATA_DIRS=/opt/rh/python27/root/usr/share${XDG_DATA_DIRS:+:${XDG_DATA_DIRS}}
# For pkg-config
export PKG_CONFIG_PATH=/opt/rh/python27/root/usr/lib64/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}

After a little investigation, I found that the reason it wasn’t being set correctly is that I was overwriting it with my own .bashrc file. Once I fixed the setting there, everything worked as expected.

Now, as far as I can tell, all the students working on this system are going to want to use the newer version of python. So I want to set it up so that the scl command is automatically run. My solution was to create a file, called in /etc/profile.d.

[profile.d]# cat 
. /opt/rh/python27/enable

Now, anyone logging in will automatically get the new python. In the event that someone needs the old version of python, I made a simple disable script that should set things back. In /opt/rh/python27, create a file called disable.

[python27]# cat disable
export PATH=/usr/lib64/qt-3.3/bin:/usr/NX/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
# For systemtap
# For pkg-config

This disable script isn’t perfect, as it just unsets LD_LIBRARY_PATH. But I think it will work for us.