设置用户环境变量
在linux中设置环境变量有几个作用域:1、当前会话;2、当前用户;3、系统环境变量
以设置java环境变量为例:
1、当前会话(只对当前会话有效)
[es@master001 ~]$ export PATH=/usr/java/test:$PATH
2、当前用户(对当前用户永久有效)
修改当前用户根目录下的
.bash_profile 或者 .bashrc
[es@master001 ~]$ vi .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
export JAVA_HOME=/home/es/java/jdk1.8.0
export PATH=$JAVA_HOME/bin:$PATH
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
export JAVA_HOME=/home/es/java/jdk1.8.0
export PATH=$JAVA_HOME/bin:$PATH
然后需要使配置文件生效:
[es@master001 ~]$ source .bash_profile
3、系统环境变量
修改 /etc/profile,在此文件中添加:
[root@master001 ~]# vi /etc/profile
..................
export JAVA_HOME=/home/es/java/jdk1.8.0
export PATH=$JAVA_HOME/bin:$PATH
..................
export JAVA_HOME=/home/es/java/jdk1.8.0
export PATH=$JAVA_HOME/bin:$PATH
同样使配置文件生效,执行:
[es@master001 ~]$ source .bash_profile
注:export PATH的环境变量是从前到后生效的,排在前面的环境变量会覆盖后面的环境变量,所以在设置用户环境变量时,新设置的环境变量最好排在$PATH的前面,例如 export PATH=$JAVA_HOME/bin:$PATH
相关推荐
昭君出塞 2020-11-23
xiaoyuerp 2020-08-17
blankt 2020-08-15
Jieen 2020-06-18
IsanaYashiro 2020-05-28
lanyou00 2020-05-26
昭君出塞 2020-05-25
zhushixia 2020-05-20
pointfish 2020-05-19
Attend 2020-05-15
屿刃 2020-04-29
lfjjia 2020-05-07
xiaohouye 2020-05-06
playlinuxxx 2020-05-05
Sabrina 2020-05-03
libao 2020-09-16
zjc 2020-09-03
84226432 2020-08-19