Creating your own modulefile

You can customize your own environment by creating and loading your own modulefiles. To use your own modulefiles you must first create a directory for them, register that directory and create the file.

Here is a step by step example:

Create and register the directory

mkdir ~/modulefiles
module use ~/modulefiles

This adds your newly created directory to the MODULEPATH environment variable and makes the files you place in there visible to the loader.

Add the ‘module use’ directive to .profile or .bashrc depending on the file you use to initialize the module package.

Create the modulefile

Use this file as an example. The content is discussed below.

#%Module1.0####################################################################
##
##  mymodule modulefile
##
##  My new module that sets my personal environment
##
proc ModulesHelp { } {
        puts stderr "\tAdds my personal stuff to the environment."
}

## Create a whatis file.  Not nessecary but cool.
module-whatis   "Adds my own personal links, aliases and paths"

## Set a few personal aliases
set-alias       "ll"    "ls -al"

## Add my bin directory to the path
append-path     PATH    ~/bin

## Set an environment variable
setenv          MY_VAR  "hello"

Explanation

  • Line 1: This line contains the syntax version that is used.
  • Line 2-6: Comments
  • Line 7-9: This is optional. This prints a module specific help when used with the ‘module help’ command.
  • Line 12: This command sets an alias.
  • Line 15: This command appends ~/bin to your PATH environment variable. You can also use prepend-path
  • Line 18: Create and set a new environment variable.