Compiling environment-modules on Ubuntu Linux

February 26th, 2015 | Categories: HPC, Linux | Tags:

Environment modules are widely used in the High Performance Computing (HPC) world where sysadmins need to install dozens, or maybe hundreds of potentially conflicting applications, libraries and compilers on multi-user machines. The University of Manchester’s Computational Shared Facility (CSF), for example, makes extensive use of environment modules and would be extremely difficult to run without them.

Once the sysadmin has correctly installed an application (MATLAB 2014a say) and set up the corresponding module file, making it available to your shell is as easy as doing

module load apps/binapps/matlab/R2014a

Unloading the module is just as easy

module unload apps/binapps/matlab/R2014a

On a heavily used, multi-user system environment modules are invaluable! Every user can have whatever compilers, libraries and applications they like — they just load and unload whatever they need from the huge selection supported by their ever-friendly sysadmins.

Environment modules on Ubuntu

I needed to install environment modules on a VM running Ubuntu 14.04 for my own use. I found a very nice setup guide at but it didn’t work. On attempting to compile, I got the error message

cmdModule.c:644:15: error: 'Tcl_Interp' has no member named 'errorLine'

This is a known bug in version 3.2.9c of environment modules and has a work-around.

I also found a set up guide at which had some useful advice on configuration..

Combining information from these sources, I managed to get a working install. Here are the steps I did in full for a clean Ubuntu 14.04 image

#Install the tcl development package
sudo apt-get install tcl-dev

#Make the directories where my modules and packages are going to live
sudo mkdir /opt/modules
sudo mkdir /opt/packages

#Get the source code. This was the most up to date version as of 25th Feb 2015

#unpack and enter source directory
tar xvzf modules-3.2.9c.tar.gz
cd modules-3.2.9

#Configure using the workaround and selecting my module folder 
CPPFLAGS="-DUSE_INTERP_ERRORLINE" ./configure --with-module-path=/opt/modules/

#make and install
sudo make install

#Edit the modulefiles path. Comment out all lines starting /usr so that only /opt/modules is used
sudo sed -i 's~^/usr~#/usr~' /usr/local/Modules/3.2.9/init/.modulespath

#Configure the shell to use modules
sudo tee /etc/profile.d/ > /dev/null << 'EOF'
# system-wide profile.modules #
# Initialize modules for all sh-derivative shells #
trap "" 1 2 3


case "$0" in
-bash|bash|*/bash) . $MODULES/init/bash ;;
-ksh|ksh|*/ksh) . $MODULES/init/ksh ;;
-sh|sh|*/sh) . $MODULES/init/sh ;;
*) . $MODULES/init/sh ;; # default for scripts

trap - 1 2 3

#Add modules to your .bashrc file
echo '#For modules' >> ~/.bashrc
echo '. /etc/profile.d/' >> ~/.bashrc

That takes care of the basic setup but modules is pretty useless at this stage. To make it useful, you need to install some extra software and the corresponding module file.

Installing a module file for Anaconda Python 2.1
This is a really simple example of how to set up a basic module file

I downloaded and installed Anaconda Python 2.1 to /opt/packages and created a file called anaconda2.1 in /opt/modules containing the following

proc ModulesHelp { } {
global dotversion
puts stderr "\tAnaconda Python 2.1 providing Python 2.7.8"
module-whatis "Anaconda Python 2.1"
prepend-path PATH /opt/packages/anaconda/bin

Now, when I do the command

module avail

I get

-------------------------- /opt/modules/ ---------------------------

I can load my anaconda2.1 module with the command

module load anaconda2.1

Now, when I type python at the command prompt, I’ll be using Anaconda’s python rather than the system python. Once I’m done, I can unload with

module unload anaconda2.1

This example is so trivial it’s almost not worth it — modules really come into their own when you need to support loads of compilers and corresponding libraries. There’s an example using gcc at

  1. Gabriel
    February 26th, 2015 at 15:45
    Reply | Quote | #1

    Why not apt-get install environment-modules?

  2. Mike Croucher
    February 26th, 2015 at 18:09
    Reply | Quote | #2

    I like to do things the hard way :)

    I just wanted to do it from scratch. I’ve no idea how the standard package is configured. This way, I know exactly.

  3. Martin Marcher
    February 28th, 2015 at 15:18
    Reply | Quote | #3

    You might want to go with easybuild and Lmod.

  4. Alastair McKinstry
    March 1st, 2015 at 15:45
    Reply | Quote | #4

    Mike: as the Debian/Ubuntu maintainer of environment-modules, if the standard package isn’t sufficient i’d like to know.

  5. Mike Croucher
    March 3rd, 2015 at 10:18
    Reply | Quote | #5

    Thanks, Alastair. I didn’t try the built in package to be honest.

    I’ve been a user of environment-modules for some time, and have also written many module files on HPC kit but had never installed it myself. I wanted to go through the compilation process and document it. This is no reflection on perceived quality of your work — I just like to take the scenic route from time to time.

  6. Saad
    July 3rd, 2015 at 08:50
    Reply | Quote | #6

    Hi Mike,

    Is there a way to load customized .bashrc upon user command “modules load bashrcApp”?

  7. Salem
    August 9th, 2015 at 09:30
    Reply | Quote | #7

    I followed your steps step by step still give me the error
    module: command not found what could be the problem ?

  8. eric
    October 1st, 2016 at 23:56
    Reply | Quote | #8

    I follow your tutorial about enviromental modules but
    I cant use module because it give me an error ERROR:102: Tcl command execution failed: source $g09root/bsd/g09.login with and without “

  9. Victor
    October 11th, 2016 at 13:25
    Reply | Quote | #9

    Perhaps the problem Salem had is that after modifying the .bashrc file he didn
    t type the command

    source ~/.bashrc

    It happened to me and I went through all the installation process again when I noticed this missing step.

    Thanks for the useful guide.