Write a module file¶
A module file is a short text file that sets the environment for one package. Write one for software you installed yourself, such as a package built under your home directory or a Miniconda, so that one module load line puts it on your path in a session or a job, in either shell.
Module files are written in Tcl, and most need three or four lines. The first line must be #%Module1.0, and the rest set or extend environment variables. man modulefile lists every command.
Write the file¶
-
Create a directory for your module files:
-
Write the file, named for the package. To put a Miniconda installation on the path:
To add a library directory:
To set several variables from one base directory:
~/modulefiles/crunch#%Module1.0 set base /home/USERNAME/crunch prepend-path PATH $base/bin prepend-path LD_LIBRARY_PATH $base/lib setenv CRUNCH $basesetmakes a Tcl variable, used only inside the file.setenvexports a variable to the shell.prepend-pathputs the directory first,append-pathlast.remove-path,unsetenv,conflictandmodule loadare the other commands used in practice. -
Load it by path and check the result:
Load it by name¶
-
Tell the module command where your files are, once, with a
~/.modulercfile: -
Load by name from then on, in sessions and in job files:
The system module files are under /share/apps/modulefiles and are the best examples of what a module file can do. module show NAME prints what any of them does.
Last updated 2026-10-03