How to use the command module (with examples)
- Linux
- December 25, 2023
The module
command is used to modify a user’s environment by loading or unloading modules. Modules are collections of software packages and environment settings that can be loaded into the user’s environment to provide specific functionalities and dependencies. This command is particularly useful in managing different versions of software packages and configuring the environment for different projects or tasks.
Use case 1: Display available modules
Code:
module avail
Motivation: By displaying the available modules, users can easily see what software packages and environment configurations are available to them. This allows them to choose the appropriate modules for their work.
Explanation: The module avail
command is used to list all the available modules in the system. It shows the names and versions of the modules, as well as any relevant module descriptions.
Example output:
--------------------- /usr/share/Modules/modulefiles ----------------------
abc/1.0 def/2.3
Use case 2: Search for a module by name
Code:
module avail module_name
Motivation: Sometimes, users may already know the name of the module they want to load, and they need a quick way to check if it is available. The module avail
command can also be used to search for a specific module by its name.
Explanation: The module avail
command can accept a module name as an argument. It then searches for modules that match the given name and displays the relevant information.
Example output:
--------------------- /usr/share/Modules/modulefiles ----------------------
module_name/1.0 module_name/2.2
Use case 3: Load a module
Code:
module load module_name
Motivation: Loading a module is necessary to make its software packages and environment settings available in the user’s current session. By loading a module, users can access the functionalities and dependencies provided by the module.
Explanation: The module load
command is used to load a specific module. It takes the module name as an argument and makes the software packages and environment settings associated with the module available in the user’s environment.
Example output:
No output is typically displayed when loading a module. However, the loaded module is now available for use in the user’s environment.
Use case 4: Display loaded modules
Code:
module list
Motivation: Users may want to verify which modules are currently loaded in their environment. This can help ensure that the correct modules are loaded and identify potential conflicts or mistakes.
Explanation: The module list
command is used to display the modules that are currently loaded in the user’s environment. It shows the names and versions of the loaded modules, as well as any relevant module descriptions.
Example output:
Currently Loaded Modules:
1) module_name/2.2
Use case 5: Unload a specific loaded module
Code:
module unload module_name
Motivation: There may be situations where a module is no longer needed in the user’s environment. Unloading a module frees up resources and removes the software packages and environment settings associated with the module.
Explanation: The module unload
command is used to unload a specific loaded module. It takes the module name as an argument and removes the software packages and environment settings associated with the module from the user’s environment.
Example output:
No output is typically displayed when unloading a module. However, the unloaded module is no longer available in the user’s environment.
Use case 6: Unload all loaded modules
Code:
module purge
Motivation: In certain cases, it may be necessary to start with a clean environment by unloading all the currently loaded modules. This can be useful when switching between different projects or tasks that require different configurations.
Explanation: The module purge
command is used to unload all the currently loaded modules. It removes the software packages and environment settings associated with all loaded modules from the user’s environment.
Example output:
No output is typically displayed when purging the modules. However, all loaded modules are no longer available in the user’s environment.
Use case 7: Specify user-created modules
Code:
module use path/to/modulefiles
Motivation: Users may have created their own modules or have access to additional modules that are not located in the default module paths. By specifying additional module paths using the module use
command, users can make these modules available for loading.
Explanation: The module use
command is used to add additional paths where modulefiles (defining modules) are located. Users can specify the path to the directory containing the modulefiles they want to access.
Example output:
No output is typically displayed when specifying user-created modules. However, the specified module path is now included in the search paths for available modules.