Customizing Your Computing Environment with Modules
7. Switching Application Environments
When switching among applications, you may need to remove the changes made by a previously loaded modulefile(s) before loading another one. There are two ways you can do this.
First, you can use the module unload and module load commands that you learned about previously. Recall that the module unload command removes the environment changes made by a modulefile. Therefore, when switching applications, you can use the module unload command to remove the changes made by your previously loaded modulefile(s) and then load your new modulefile using the module load command.
The second way is to use a single Modules command that lets you switch between applications by unloading one modulefile and loading another. This command is appropriately called module switch. Note that the module swap command and the module switch commands are equivalent, and only the name differs. If you try one of them on your system and you get an error message, use the other one. On some systems, you can use either one.
The syntax for the module switch command is:
module switch modulefile1 modulefile2
where modulefile1 is the currently loaded modulefile, and modulefile2 is the modulefile you want to load.
For example, to switch to another version of Matlab, say version 9.4, you would enter:
$ module switch matlab/9.7 matlab/9.4
Entering the module list command, we see that the switch was made.
$ module list Currently Loaded Modulefiles: 1) torque/6.1.2 2) moab/9.1.2 3) env/ncsa 4) env/taub 5) matlab/9.4 6) java/1.8
Exercises
Complete the following exercises by entering the appropriate module command on your system's command line:
Exercise 1: In the last section's exercises, you used the module load command to load a modulefile of your choice. Now, remove it and show that it is no longer in your shell environment.
You can unload the modulefile using the module unload command. Use the module list command to show that it is no longer loaded in your environment. For example:
$ module unload matlab/9.7 $ module list Currently Loaded Modulefiles: 1) torque/6.1.2 2) moab/9.1.2 3) env/ncsa 4) env/taub 5) java/1.8
Exercise 2: You have java/1.8 loaded into your software environment. What single module command would you enter to switch it to another version?
First, enter the module avail command to see which versions of java are available on a system:
$ module avail java ------------------------------------------------ /usr/local/modulefiles ------------------------------------------------ java/1.8(default) java/10 java/11 java/12 java/13 java/9
Say you want to switch it to version 9. To do this, enter the following command:
$ module switch java java/9
Note that you do not have to enter the full pathname to specify the default version, although it works if you do.
Use the module list command to show that you switched to version 9:
$ module list Currently Loaded Modulefiles: 1) torque/6.1.2 2) moab/9.1.2 3) env/ncsa 4) env/taub 5) java/9