Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Ubuntu 環境變數設定檔載入順序詳解:五大檔案優先級與 source 即時生效

編輯:Linux 系統常見問題解答

五大設定檔與角色

檔案層級載入時機說明
/etc/environment系統登入最早 (PAM)所有進程環境變數,非 Shell 腳本,僅 KEY=VALUE 格式
/etc/profile系統登入 Shell 第二所有使用者環境變數
/etc/bash.bashrc系統每次開啟互動式 bash系統級別名、函數
~/.profile使用者登入 Shell 第三當前使用者個人環境
~/.bashrc使用者每次開啟互動式 bash當前使用者別名、函數

載入順序

/etc/environment → /etc/profile → ~/.profile → /etc/bash.bashrc → ~/.bashrc

即時生效指令

source /etc/profile
source ~/.bashrc
# 或重新開啟終端機 / 重新登入

注意: /etc/environment 非 Shell 腳本,不可包含邏輯判斷或指令替換,僅純環境變數定義。

Copyright © Windows教程網 All Rights Reserved