17

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.

6
  • 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, 2018 at 14:59
  • Have you tried closing Terminal.app and starting it over?
    – jksoegaard
    Feb 20, 2018 at 15:00
  • yes. i have created bashrc file. (and run source ~/.bash_profile)
    – hqt
    Feb 20, 2018 at 15:01
  • @jksoegaard yes. I have restarted terminal app.
    – hqt
    Feb 20, 2018 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, 2018 at 15:32

3 Answers 3

27

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

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

You can edit your environment in ~/.zprofile instead of ~/.bash_profile. Then, reopen a terminal.

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