Environment Modules allow for management of environment variablesĀ when using multiple compilers, multiple libraries, or even versions of applications that you might need to run. Rather than change $PATH, $LD_LIBRARY_LOAD, or $MANPATH for each you can use Environment Modules to handle the path changes to ensure you run the appropriate version correctly.
Installation
On CentOS etc:
yum install environment-modules
On Ubuntu/Debian-esque:
sudo apt-get install environment-modules
Usage
Important: Log out and log back in again
Then check the modules that are currently available:
module avail module list
Adding a Module
I’d like to add a module to set an alternative GCC compiler. The system version of GCC was atĀ /usr/bin/gcc and was version 4.4.7. A more updated version 4.9.0 was comiled under /var/shared/gcc-4.9.0
To add an Environment Module for my custom GCC version 4.9.0, I did the following:
cd /usr/share/Modules/modulefiles/ mkdir compilers cp /usr/share/Modules/modulefiles/modules /usr/share/Modules/modulefiles/compilers/gcc-4.9.0
The modules file copied above is a useful template but I amended a file by Jeff Layton from admin-magazine.com :
#%Module1.0##################################################################### ## ## modules compilers/gcc-4.9.0 ## ## modulefiles/compilers/gcc-4.9.0 by jonny based on admin-magazine.com Jeff Layton ## proc ModulesHelp { } { global version modroot puts stderr "compilers/gcc-4.9.0 - sets the Environment for GCC 4.9.0 in /var/shared " } module-whatis "Sets the Environment for using the GCC compiler version 4.9.0" # for Tcl script use only set topdir /var/shared/gcc-4.9.0 set version 4.9.0 set sys linux86 setenv CC $topdir/bin/gcc-4.9.0 setenv GCC $topdir/bin/gcc-4.9.0 setenv FC $topdir/bin/gfortran-4.9.0 setenv F77 $topdir/bin/gfortran-4.9.0 setenv F90 $topdir/bin/gfortran-4.9.0 prepend-path PATH $topdir/include prepend-path PATH $topdir/bin prepend-path MANPATH $topdir/share/man/ prepend-path LD_LIBRARY_PATH $topdir/lib prepend-path LD_LIBRARY_PATH $topdir/lib64
To activate this environment:
module avail module load compilers/gcc-4.9.0
Now if I run module list I can see the new module has been added:
module list
If I run:
which gcc
I should see:
/var/shared/gcc-4.9.0/bin/gcc
This assumes that there is a binary named gcc in /var/shared/gcc-4.9.0/bin – if there is not create a symbolic link to it. For example, I needed to do:
cd /var/shared/gcc-4.9.0/bin ln -s ./gcc-4.9.0 ./gcc
Unloading Modules
To unload a module and return to using the system provided paths:
module unload compilers/gcc-4.9.0 module list
This should show no modules and running ‘which gcc’ should show the system gcc again:
I can now distribute the /usr/share/Modules/modulefiles/compilers/gcc-4.9.0 file among the cluster via Puppet for use on any cluster node.