Why do I need to source bash_profile every time

后端 未结 6 1356
[愿得一人]
[愿得一人] 2021-02-04 01:28

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

相关标签:
6条回答
  • 2021-02-04 01:57

    On Mac Catalina, I just had to open "preferences" on terminal and change the "shells open with" from "default" to "Command(complete path)", which the default path was "/bin/zsh". touch ~/.zshrc, if that file doesn't exist already, and copy/paste your stuff from ".bash_profile" into the ".zshrc" file.

    0 讨论(0)
  • 2021-02-04 02:11

    Now that we've narrowed down the problem:

    1. Run ps -p $$ at the command line to determine that you are, in fact, using a bash shell.
    2. Realize that you are in zsh, which means you should be editing your profile in .zshrc.
    3. Copy the offending lines from .bash_profile to .zsh, OR
    4. 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.

    0 讨论(0)
  • 2021-02-04 02:13

    Terminal -> Preference -> profile -> Shell -> Run command : source ~/.bash_profile

    Tick on run inside shell.

    After doing all those , just logout and check weather everything works fine or not

    0 讨论(0)
  • 2021-02-04 02:13

    Go to “Preferences/Profiles then look in the right window and find “shell”.

    Once in that if your “Startup Run Command” hasn’t been turned on. Click the box to turn it on and in the command section type:

    (If you made a .zsh file)

    source .zsh ; clear 
    

    (If you made a .bash_profile)

    source .bash_profile ; clear
    

    Doing this ; clear

    Will clear your terminal to a new page so that you don’t see your terminal display:

    “Last login: etc 
    User@user-Mac ~ % source .zsh
    

    If you typed the commands as I said you should just get this:

    User@user-Mac ~ % 
    

    That way you will be greeted with a clear page with no extra jumbo. Also to make sure that your .zsh or .bash_profile aliases work type the following command to see a list of your custom aliases:

    Alias 
    

    One alias I like to do is

    alias LL=“ls -la”
    

    This will display a tree or the directory you are in as well as hidden files.

    If this helped you or you have questions let me know!

    0 讨论(0)
  • 2021-02-04 02:18

    Not sure if this is the best solution but it works.

    sudo nano /etc/bashrc and change that, restarted the terminal and it finally remembered with command. Tried ~/.bash_profile and ~/.bashrc without success, just wasn't sourcing it.

    0 讨论(0)
  • 2021-02-04 02:22

    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.

    0 讨论(0)
提交回复
热议问题