2

I have installed some command lines (i.e: rbenv ...), but every time I start new terminal tab, it looks like those environment reset. I must manually call again:

source ~/.bash_profile

I followed some tutorials. i.e I put this code in .bash_profile but It doesn't work

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

This is not happen in my old mac. I don't know how to configure this. Thanks

  • 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
4

.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
  • I pasted your three lines into my .bashrc file and it generated an error message. – jmh Apr 22 at 15:18
2

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
  • thanks this worked perfectly – Vincent Tang May 7 at 0:32

You must log in to answer this question.

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