Creating a module for yourself

There may be a situation in which it makes best sense to install software for yourself or for your group. It can be convenient to create a module file for it and use the module command to make it available for yourself and others. For the examples that follow, the fictional user grundoon will be used. Your uniqname should appear where grundoon appears here.

Creating a module for a program with one version

The first step is to install whatever software will be made accessible by the module you create. For the sake of this example, let us assume that the software is installed into your home directory in a utilities subdirectory. The software has one executable, hello, and it has one library,, that is needed. The installation creates the standard directories under ~/utilities, namely, ~/utilities/bin and ~/utilities/lib. To set up the environment manually, you would need to run these commands.

$ export PATH=~/utilities/bin:${PATH}
$ export LD_LIBRARY_PATH=~/utilities/lib:${LD_LIBRARY_PATH}

To convert this to a module, create a file in your ~/privatemodules directory called utilities and insert the following lines.


set     version         1.0
set     app             utilities
set     modroot         ~/utilities

prepend-path  PATH             $modroot/bin
append-path   LD_LIBRARY_PATH  $modroot/lib

The first line is required to identify this as a module file. The next three lines set variables that the module command can use when it is run. The first sets the version number, the second the application name, and the third sets the root directory for the application.

The prepend-path command instructs module to add to the front of your PATH the directory ~/utilities/bin (filling in the value of $modroot). The append-path command instructs module to add to the back of your LD_LIBRARY_PATH the directory ~/utilities/lib.

In this case, we want to be sure that our version of hello is used before any others in the PATH, but we are confident that there are no other libraries, so we add to the end of LD_LIBRARY_PATH.

Once that file is created, you can display it with

$ module av utilities
------------------------- /home/grundoon/privatemodules -------------------------

$ module show utilities

prepend-path	 PATH ~/utilities/bin 
prepend-path	 LD_LIBRARY_PATH ~/utilities/lib 

Creating a module for a program with multiple versions

If you need to have multiple versions of your program available, you can create a module for each version. To make our utilities module example into a versioned module, create a subdirectory called utilities instead of a file, then put the module definition into a file named for the version, for example, 1.0, within the utilities directory. Doing so would result in

$ cd privatemodules
$ ls
default  utilities

$ ls utilities

$ cat utilities/1.0
set     version         1.0
set     app             utilities
set     modroot         ~/utilities

prepend-path  PATH  $modroot/bin
prepend-path  LD_LIBRARY_PATH  $modroot/lib

and you would load it with

$ module load utilities

If, at some point, you create a module file for version 1.1, you would create a module file called ~/privatemodules/utilities/1.1, after which module load utilities would load version 1.1, and you would have to use

$ module load utilities/1.0

to load the older version. However, there may be occasions when you want the older version to be the default, for example, if you have projects underway that use the older version, but you have a new project that needs a feature in the new version. You can set a default version by creating a file called .version in the program’s module directory. For example, to make version 1.0 the default version for the utilities module, put the lines

set ModulesVersion "1.0"

into ~/privatemodules/utilities/.version. Note, again, that the first line is required to mark it as a module command file. This will give

$ module av utilities

------------------------- /home/grundoon/privatemodules -------------------------
utilities/1.0(default) utilities/1.1

and module load utilities will, once again, load version 1.0.