暫時
通過 Shell 命令 export 直接修改 Linux 環(huán)境變量
使用 export 設(shè)置的變量光稼,只對當(dāng)前終端 Shell 有效
適合設(shè)置一些臨時變量
sudo export PATH=$PATH:/usr/local/hadoop/bin
用
echo $PATH
來查看環(huán)境配置信息
永久
全局環(huán)境變量,設(shè)置的是所有用戶的環(huán)境
/etc/profile /etc/bashrc /etc/environment
全局環(huán)境變量朗若,設(shè)置的是整個系統(tǒng)的環(huán)境
/etc/environment
只對單個用戶生效水孩,當(dāng)用戶登錄時該文件僅執(zhí)行一次
~/.bash_profile
~/.profile
用戶可使用該文件添加自己使用的 shell 變量信息
另外在不同的LINUX操作系統(tǒng)下满葛,這個文件可能是不同的
可能是
~/.bash_profile
~/.bash_login
~/.profile
其中的一種或幾種
如果存在幾種的話径簿,那么執(zhí)行的順序便是
~/.bash_profile、 ~/.bash_login嘀韧、 ~/.profile
比如 Ubuntu 系統(tǒng)一般是 ~/.profile 文件
只對單個用戶生效篇亭,當(dāng)?shù)卿浺约懊看未蜷_新的 shell 時,該文件被讀取
~/.bashrc
sudo gedit ~/.profile(or .bashrc)
修改內(nèi)容
export PATH=/usr/local/cuda/lib64:$PATH
or
PATH=/usr/local/cuda/bin:$PATH
export PATH
保存設(shè)置
source profile
Problem& Solution
Problem_0
在 /etc/profile 下修改的路徑锄贷,source 完 /etc/profile 后译蒂,
關(guān)閉當(dāng)前進(jìn)程,
卻發(fā)現(xiàn)新寫的路徑在 新的 進(jìn)程窗口 中無法被讀入
Solution
原因未知
在 ~/.bashrc 文件末尾添上一句話 :
source /etc/profile
source 該文件 :
source ~/.bashrc
這樣每次啟動該用戶谊却,都會 自動 source 一遍 /etc/profile