Environment Module Files

TL:DR; A howto on environment modules files, for maintaining software along with the packages provided by your distribution.

Environment module files are a nice way to provide multile versions of different packages for users. In our network, we provide a nfs mounted /opt-Partition which contains every software which isn’t supported (either in no way, or in different versions) by our distribution.

We put all packages in /opt/packkages/\$packagename-\$version/. When compiling packages, we use --prefix=/opt/packkages/\$packagename-\$version/, which makes it easy to use for example a library like openmpi.

To install environment modules from the scratch, download the tar.gz from http://sourceforge.net/projects/modules/.

The following at least worked for VERSION=3.2.10.

# Unpack tar xvf modules-$VERSION.tar.gz
# Change directory
cd modules-$VERSION
# Configure (I'm using a network shared /opt partition)
./configure --prefix=/opt/packages/modules/
# Build and install
make && make install
# create default link (i have no idea, why this 
# isn't done by "default"
cd /opt/packages/modules/Modules/
ln -s $VERSION default
# return to the source directory
cd -
# copy profile script to a profile.d directory 
# (in my case again on /opt)
cp etc/global/profile.modules /opt/etc/profile.d/profile.modules.sh
# edit module configuration
vim /opt/packages/modules/Modules/$VERSION/init/.modulespath
# i just commented out all lines and add /opt/modules where
# i put my module files

The next step is, to create the module files. I suggest to keep them as clean and small as possible. Using Variables makes them easy to copy n paste (for example, if you update a library to a new version and want to keep the old version too).

Beware, there are many strange module files to find in the web. I suggest to write them by yourself and use only commands you know and environment variables from which you know what they are doing.

First example cmake, which I build using:

# Download
wget http://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz
# Extract
tar xzf cmake-2.8.12.2.tar.gz
# create build directory
mkdir -p cmake-2.8.12.2/build; cd cmake-2.8.12.2/build
# configure
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/packages/cmake-2.8.12.2
# make and install 
make -j4 && make install

whichs results in a driectory which looks like this

ls /opt/packages/cmake-2.8.12.2/
bin  doc  man  share
So i create a module file /opt/modules/cmake/2.8.12.2 which makes cmake easy useable:
#%Module1.0
#####################
# CMake Module file
 
set package "cmake"
set version "2.8.12.2"
set dir "/opt/packages/$package-$version"
 
# Defines String that is displayed when command "module whatis" is invoked
module-whatis "$package/$version - sets the environment variables to use $package in $dir"
 
 
if { ! [ file exists $dir ] } {
	puts stderr "$package-$version is not available on this machine. directory $dir not found"
	exit 1
}
 
# Set Conflicts: Defines modulefiles that can not be loaded at the same time
conflict $package
 
prepend-path PATH	$dir/bin
prepend-path MANPATH	$dir/man

What a module does, can be tested by using module show:

$ module show cmake/2.8.12.2 
---------------------------------------------------------------
/opt/modules/cmake/2.8.12.2:
 
module-whatis	 cmake/2.8.12.2 - sets the environment variables
             	 to use cmake in /opt/packages/cmake-2.8.12.2
conflict	 cmake 
prepend-path	 PATH /opt/packages/cmake-2.8.12.2/bin 
prepend-path	 MANPATH /opt/packages/cmake-2.8.12.2/man 
---------------------------------------------------------------

next, load the module, and check if we got the right cmake version:

# load module
$ module load cmake/2.8.12.2 
# check which binary is used
$ which cmake
/opt/packages/cmake-2.8.12.2/bin/cmake
# check version
$ cmake --version
cmake version 2.8.12.2

I hope this little howto will help somebody (at least me, if i have to install module files again somewhere else). Commends welcome.

Hint: Useful documentation I’ve used: