$ JAVA_HOME路径在登录时未在〜/ bash_profile中正确获取 [英] $JAVA_HOME path not sourced correctly in ~/bash_profile at login
问题描述
登录我的CentOS 7 VM后,我的$ JAVA_HOME始终设置为:
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-11。 b12.el7.x86_64 / jre
,这是不正确的。
Upon logging into my CentOS 7 VM, my $JAVA_HOME is always set to :
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x86_64/jre
, which is incorrect.
我的〜/ .bash_profile读取:
My ~/.bash_profile reads:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.144-0.b01.el7_4.x86_64/jre
export JAVA_HOME
PYCHARM_HOME=/opt/pycharm-community-2017.2.3/
export PYCHARM_HOME
ECLIPSE_HOME=/opt/eclipse
export ECLIPSE_HOME
export SPARK_HOME=/opt/spark
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$JAVA_HOME/bin:$SPARK_HOME/bin:$PYCHARM_HOME/bin:$ECLIPSE_HOME
export PATH
每次打开新终端时出现.bash_profile似乎都可以解决问题,但为什么我的$ JAVA_HOME路径在启动时默认为旧版本而未设置为.bash_profile中指定的目录?
Sourcing .bash_profile each time I open a new terminal appears to correct the issue, but why is my $JAVA_HOME path defaulting to an old version on startup and not being set to the directory specified in .bash_profile?
推荐答案
每次打开新终端时,采购.bash_profile都会出现
更正问题,但为什么我的$ JAVA_HOME路径在启动时默认为旧的
版本而未设置为
.bash_profile中指定的目录?
Sourcing .bash_profile each time I open a new terminal appears to correct the issue, but why is my $JAVA_HOME path defaulting to an old version on startup and not being set to the directory specified in .bash_profile?
您需要从当前用户退出并再次登录,以便更改环境变量。
You need to logout from current user and login again so environment variables changes take place.
可能有用
在Bash中:
- Bash作为登录shell将加载
/ etc / profile
,〜/ .bash_profile
,〜/ .bash_login
,〜/ .profile
在订单中。 - Bash作为非登录交互式shell将加载
〜/ .bashrc
- Bash as login shell will load
/etc/profile
,~/.bash_profile
,~/.bash_login
,~/.profile
in the order. - Bash as non-login interactive shell will load
~/.bashrc
环境:
-
使用
/ etc / environment
永久系统范围(所有用户,所有进程)设置环境变量fo所有用户。
Use
/etc/environment
to permanently system wide (all users, all processes) set environmental variables for all users.
/ etc / environment
是一个系统范围的配置文件,这意味着它被所有用户使用。它由root拥有,所以你需要成为管理员用户并使用sudo来修改它。
/etc/environment
is a system-wide configuration file, which means it is used by all users. It is owned by root though, so you need to be an admin user and use sudo to modify it.
假设你设置 foo =可以从所有用户会话访问bar
变量 foo
。要测试变量输出第一个来源
Suppose if you set foo="bar"
variable foo
will be accessible from all the user sessions. To test the variable output first source it
source / etc / environment
〜/ .profile
是您自己用户的个人shell初始化脚本之一。每个用户都有一个,可以编辑他们的文件,而不会影响其他人。
~/.profile
is one of your own user's personal shell initialization scripts. Every user has one and can edit their file without affecting others.
/ etc / profile
和 /etc/profile.d / * .sh
是全局初始化脚本,相当于〜/ .profile
用户。全局脚本在用户特定脚本之前执行;主 / etc / profile
执行 / etc /中的所有
就在退出之前。 * .sh
脚本profile.d /
/etc/profile
and /etc/profile.d/*.sh
are the global initialization scripts that are equivalent to ~/.profile
for each user. The global scripts get executed before the user-specific scripts though; and the main /etc/profile
executes all the *.sh
scripts in /etc/profile.d/
just before it exits.
另请注意,
-
/ etc / environment
文件为登录时的每个用户设置系统范围的变量。 - 如果任何用户打开了bash shell,则会执行
bash_profile
中的命令。因此,除非至少打开一次bash shell,否则不会设置变量。
- The
/etc/environment
file sets the variable system wide for every user on login. - Commands in the
bash_profile
are is executed if the bash shell is opened by any user. So the variables would not be set unless a bash shell is opened at least one time.
这篇关于$ JAVA_HOME路径在登录时未在〜/ bash_profile中正确获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!