Master Linux Environment Modules: Install, Configure, and Manage Multiple Software Versions
This guide explains how to install the Linux module‑environment tool, initialize it, use common commands, write modulefiles, manage multiple MODULEPATH entries, set default versions, and apply a global configuration for seamless handling of diverse software versions.
Introduction
When multiple versions of the same software need to coexist on a Linux system, managing environment variables manually is cumbersome. The module (module‑environment) tool provides a fast way to load and unload versioned environments.
Official documentation
Documentation URL: https://modules.readthedocs.io/en/latest/module.html
Installation
module is implemented in Tcl (≥8.4). Current stable release 4.4.1 requires Tcl 8.5+. Install via package manager or from source.
Red Hat / CentOS: yum install environment-modules Debian / Ubuntu:
apt-get install environment-modulesInitialization
module is not a binary; you must source its init script for your shell. Typical paths: source /usr/share/modules/init/bash # Bash or source /usr/share/modules/init/csh # C shell If the directory is /usr/share/module instead of modules, adjust the path accordingly.
Common commands
module avail– list all modulefiles found in
MODULEPATH module load <name>[/<version>]or module add – load a module module unload <name> or module rm – unload a module module list – show currently loaded modules
MODULEPATH and modulefile discovery
The environment variable MODULEPATH holds a colon‑separated list of directories that contain modulefiles. When module runs, it recursively scans each directory in MODULEPATH and makes every file it finds available as a module.
Directory layout and modulefile example
A common layout is a root directory (e.g. /soft) with sub‑directories for each software package and further sub‑directories for each version. Each version directory contains a single modulefile.
Example layout for GCC:
/soft/
└── gcc/
├── 4.8.4/
│ └── modulefile
├── 4.9.3/
│ └── modulefile
└── .versionExample modulefile for gcc/4.8.4:
#%Module1.0
setenv GCC_HOME /software/gcc/4.8.4/
prepend-path PATH /software/gcc/4.8.4/binKey directives: #%Module1.0 – identifies the file as a modulefile. setenv – defines an environment variable. prepend-path – adds a directory to the front of an existing path variable (e.g., PATH).
Multiple MODULEPATH entries
Set MODULEPATH to a colon‑separated list, e.g.: export MODULEPATH=/soft:/soft1:/soft2 module will search all listed directories.
Default version with .version file
Place a file named .version in the same directory as the version modulefiles to specify which version should be loaded when the package name is used without an explicit version.
#%Module1.0
set ModulesVersion "4.9.3"After creating the file, module avail marks that version with (default) and module load gcc loads it automatically.
Global configuration for multi‑user systems
Create a shared initialization script (e.g., /etc/module.cshrc or /etc/module.bashrc) that sources the appropriate init file and then symlink it into each user’s home directory: ln -s /etc/module.cshrc /home/username/.cshrc Users can add personal customisations by creating a file such as cshrc.own that the global script sources.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
