The MODULES_UNLOAD_MATCH_ORDER environment variable is introduced to set whether the firstly or the lastly loaded module should be selected for unload when multiple loaded modules match unload request.

Configure option --with-unload-match-order defines this setting which can be superseded by the environment variable. By default, lastly loaded module is selected and it is recommended to keep this behavior when used modulefiles express dependencies between each other.

This new feature is available in git repository and will be included into the upcoming v4.3 release.