# Environment Module ## 簡介 - 一種讓使用者可以**動態管理環境變數**的工具。 - 避免環境變數衝突。 - 方便不同軟體版本共存(如 Python 3.8 / 3.9)。 ## 安裝與設定 ### 安裝 ```bash= sudo apt install environment-modules ``` ### 啟用 modules ```bash= source /etc/profile.d/modules.sh ``` 為了避免每次重開 terminal 都要使用指令,可以將它寫進 `/etc/profile`。 ```bash= echo 'source /etc/profile.d/modules.sh' | sudo tee -a /etc/profile ``` ## 基本使用方法 ### 列出可用模組 ```bash= module avail ``` ### 載入模組 ```bash= module load <module_name> ``` #### 範例: 載入 cuda/11.8 版本 ```bash= module load cuda/11.8 ``` ### 檢視當前載入的模組 ```bash= module list ``` ### 卸載模組 ```bash= module unload <module_name> ``` #### ex. ```bash= module unload cuda/11.8 ``` ### 切換模組版本 ```bash= module switch <old_module> <new_module> ``` #### ex. ```bash= module switch cuda/11.8 cuda/12.0 ``` ### 清除所有已載入的模組 ```bash= module purge ``` ## Modulefile ### 建立自訂 module - 自訂 module 存放於 `/usr/share/modules/modulefiles/` 或 `/etc/modulefiles/`。 - 也可以建立 `~/modules/` 來存放個人模組。 ### 範例 `/usr/share/modules/modulefiles/` ``` │── core/ # 基礎環境模組 │ ├── null │── compiler/ # 編譯器相關模組 │ ├── gcc/ │ │ ├── 8.4 │ │ ├── 9.3 │ │ ├── 10.2 │ │ └── 11.1 │ ├── llvm/ │ ├── 12.0 │ ├── 13.0 │── mpi/ # MPI 並行運算庫 │ ├── openmpi/ │ │ ├── 4.0.5 │ │ ├── 4.1.0 │ │ └── default -> 4.1.0 # 指向最新版本 │── apps/ # 各種應用程式 │ ├── python/ │ │ ├── 3.8 │ │ ├── 3.9 │ │ ├── 3.10 │ │ └── default -> 3.10 │ ├── myapp/ │ ├── 1.0 │ ├── 2.0 │ └── default -> 2.0 ``` ### Modulefile 範例 #### cuda/11.8 ```bash= #%Module1.0 ## ## CUDA 11.8 modulefile ## set cuda /usr/local/cuda-11.8 prepend-path PATH $cuda/bin prepend-path LD_LIBRARY_PATH $cuda/lib64 ``` ### Module use(指定額外的 modulefile 目錄) #### ex. ```bash= module use ~/modules ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up