| 層級 | 檔案 | 生效範圍 | 載入時機 | 修改生效方式 |
|---|---|---|---|---|
| 系統級 | /etc/profile | 所有使用者 | 登入 Shell (第一次登入) | 重啟機器或重新登入 |
/etc/bashrc | 所有使用者 | 每次開啟互動式 bash | 重新開啟終端機或 source /etc/bashrc | |
| 使用者級 | ~/.bash_profile | 當前使用者 | 登入 Shell (僅一次) | 重新登入 |
~/.bashrc | 當前使用者 | 每次開啟互動式 bash | 重新開啟終端機或 source ~/.bashrc |
/etc/profile → /etc/profile.d/*.sh → ~/.bash_profile → ~/.bashrc → /etc/bashrc
/etc/profile:系統級環境變數 (PATH、JAVA_HOME 等),需重啟/重新登入生效。/etc/bashrc:系統級別名、提示字元、函數定義,即時生效。~/.bash_profile:使用者級環境變數,通常呼叫 ~/.bashrc。~/.bashrc:使用者級別名與函數,即時生效。實務建議: 永久環境變數改 /etc/profile 或 ~/.bash_profile;別名/函數/提示字元改 /etc/bashrc 或 ~/.bashrc;修改後 source 對應檔案即時生效,免重啟。