问题
I have installed Hadoop and every time I want to run it, first I have to do this:
source ~/.bash_profile
or it won't recognize the command hadoop
Why is that?
I am on OSX 10.8
回答1:
Now that we've narrowed down the problem:
- Run
ps -p $$
at the command line to determine that you are, in fact, using a bash shell. - Realize that you are in zsh, which means you should be editing your profile in
.zshrc
. - Copy the offending lines from
.bash_profile
to.zsh
, OR Modify your.zshrc
to directly source your.bash_profile
.
UPDATE: Do what @TC1 mentions in the comments and keep the shell-specific code in each shell's own profile, and from those profiles, only source shell-agnostic code.
回答2:
I tried the approved answer. Changing the .zshrc file works for one of my machines. But for the other one, when I run ps -p $$, it is -sh under the command. And I changed both bash and zsh files, neither of them works for me this time.
So I found this https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html
it mentioned "When Bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. "
so I went to that file /etc/profile and add "source ~/.bashrc" in that file. Then it works since every time a terminal is opened, it runs the command in that /etc/profile file.
来源:https://stackoverflow.com/questions/15733508/why-do-i-need-to-source-bash-profile-every-time