1、vi /etc/profile
2、輸入大寫G,定位內容末尾。
3、在末尾輸入
export PATH=/home/order/soft/jdk
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$JAVA_HOME/bin
我的
PATH=$PATH:/usr/local/src/nodejs/bin
export PATH
保存退出
4、source /etc/profile
5、輸入java -version
其他的三種方法:
總結3種方法:
1、修改/etc/profile
1.1 :首先在此文件中設置環境變量;
1.2:export 設置好的環境變量.
#view /etc/profile
export PATH="變量路徑"
2、修改.bashrc
# vim /root/.bashrc
export PATH="變量路徑"
3、直接在shell下用export命令修改
#export PATH="$var_PATH"
#export 可查看當前系統下的所有環境變量.
查看當前環境變量
echo $PATH
保存並生效
source /etc/profile