linux環境變數新增
阿新 • • 發佈:2021-12-13
目錄
一:linux環境變數載入檔案
1.在linux中新增環境變數怎麼新增呢? 檔案內 /etc/profile /etc/bashrc 家目錄內 ~/.bash_profile ~/.bash_rc 資料夾內: /etc/profile.d/ 2.增加環境變數有兩種方式: 1.臨時新增 2.永久新增 增加環境變數的格式: export PYTHON_HOME = 'D:\python' export 變數 = 變數值 檢視本機的環境變數: echo $PYTHON_HOME : 檢視某一個環境變數 printenv :檢視所有的環境變數
1.新增環境變數順序
1.進入環境變數檔案編輯
vim /etc/profile
2.增加環境變數
export 變數 = 變數值
3.檢視本機的環境變數
echo $[變數] :檢視某一個環境變數
printenv : 檢視所有的環境變數
2.系統環境變數執行順序
讀取環境變數的幾種情況,並且測試出使用檔案的先後順序 1、重啟後環境變數執行順序 /etc/profile.d --> /etc/profile --> /etc/bashrc --> ~/.bashrc --> ~/.bash_profile 2、切換其他使用者後環境變數執行順序 /etc/profile.d --> /etc/bashrc --> ~/.bashrc 知識儲備: useradd [使用者名稱] 建立使用者 su [使用者名稱] 切換使用者 3、重新登入使用者後環境變數執行順序 1、su - [使用者名稱] /etc/profile.d --> /etc/profile --> /etc/bashrc --> ~/.bashrc --> ~/.bash_profile ssh [使用者名稱][使用者伺服器] 2、ssh [email protected] 以使用者名稱和登入伺服器 /etc/profile.d --> /etc/profile --> /etc/bashrc --> ~/.bashrc --> ~/.bash_profile 推薦使用:如果要想在所有的使用者都生效的環境變數 根: /etc/profile.d --> /etc/bashrc 當前目錄生效 家目錄: ~/.bash_profile --> ~/.bash_rc