4

I installed some command line programs (e.g. rbenv), but every time I open a new Terminal tab, it looks like the environment gets reset. I need to source my .bash_profile manually:

source ~/.bash_profile

I followed some tutorials and put this code in my .bash_profile, but it doesn't work:

if [ -n "$BASH_VERSION" ] && [ -f $HOME/.bashrc ];then
    source $HOME/.bashrc
fi

This doesn't happen on my old Mac, and I don't know how to configure this.

  • What do you mean by the code "doesn't work"? - How doesn't it work? - Do you actually have a .bashrc file? – jksoegaard Feb 20 '18 at 14:59
  • Have you tried closing Terminal.app and starting it over? – jksoegaard Feb 20 '18 at 15:00
  • yes. i have created bashrc file. (and run source ~/.bash_profile) – hqt Feb 20 '18 at 15:01
  • @jksoegaard yes. I have restarted terminal app. – hqt Feb 20 '18 at 15:01
  • And what is your problem exactly? - That the code inside .bash_profile is not run? - or that the code inside your .bashrc file is not run? Are you sure you named it ".bashrc" and not "bashrc" (note the leading dot) – jksoegaard Feb 20 '18 at 15:32
8

If you are using oh-my-zsh, the default one that will be loaded automatically is ~/.zshrc. All you need to do is adding the following at the end of ~/.zshrc:

if [ -f ~/.bash_profile ]; then
  . ~/.bash_profile
fi
| improve this answer | |
  • 2
    thanks this worked perfectly – Vincent Tang May 7 '19 at 0:32
  • 1
    after updating to Catalina I got the message on the terminal if I wanted to switch to zsh, I did and all hell broke loose. Thanks, good human. – dresh Dec 20 '19 at 9:44
5

.bashrc will be loaded per default, so if you have all your stuff in .bash_profile ensure it will be loaded, so you have to add to your .bashrc:

if [ -f ~/.bash_profile ]; then
  . ~/.bash_profile
fi
| improve this answer | |
  • I pasted your three lines into my .bashrc file and it generated an error message. – jmh Apr 22 '19 at 15:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .