1.export 變量名=value
2.變量名=value ; export 變量名
3.declare -x 變量名=value
1.編輯 /etc/profile
<code>vim /etc/profile</code>

2.使定義的全局環境變量生效
root@raspberrypi:~# source /etc/profile
或者
root@raspberrypi:~# . /etc/profile
3.驗證
對于使用者的 環境變量設定,比較常見的是使用者家目錄下的 ./.bashrc 和 ./.bash_profile 這兩個檔案。一般推薦在 .bashrc 中優先設定
常見的全局環境變量的配置檔案有:/etc/profile /etc/bashrc /etc/profile.d 。一般推薦在 /etc/bashrc 裡優先設定。
若要在登陸後初始化或顯示加載内容,則把腳本檔案放在/etc/profile.d/下即可(無需加可執行權限)