$JAVA_HOME path not sourced correctly in ~/bash_profile at login

廉价感情. 提交于 2019-12-06 15:30:24
  1. Run ps in the interactive shell to make sure you're in bash.
  2. Try bash -l after login and see if it fixes your problem.
  3. Add set -x before JAVA_HOME=... to check if there's something wrong.

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.

May be useful

In Bash:

  • 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

Environment :

  • Use /etc/environment to permanently system wide (all users, all processes) set environmental variables for all users.

    /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.

    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 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 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.

Also note,

  • 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.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!