.bash_profile not sourced

I have a .bash_profile file that I added some stuff to (aliases and color and some git stuff) and when I open iTerm and source it then everything's fine and I have everything but when I close iTerm and reopen it then no colors and no aliases until I source it again.

What should I do to permanently source it?

Is it maybe sourcing another file? How can I check that?

EDIT: I checked my iTerm preferences, and the "login shell" option is checked so I imagine it should source it when i open iTerm.


Solution 1:

It's also possible that your terminal shell is defaulting to sh instead of bash. You can verify this first:

 $ echo $SHELL
 /bin/tcsh

To change this to bash, you can go into your Terminal -> Preferences -> Startup tab, and change "Shell Opens With:" from "Default login shell" to Command and value "/bin/bash".

Alternately, you can change your default shell by executing the following command at the command prompt:

chsh -s bin/bash

After you do one of these, open a new shell window, and your .bash_profile should be sourced.

Solution 2:

Ok so I dug deeper into it and it's trying to source .profile and I, instead, had .bash_profile. So I created a ~/.profile file and copied the content of .bash_profile into it, and then - WORKS! It is sourced whenever I start iTerm or Terminal.

Solution 3:

.profile, .bash_profile and similar files are only sourced by "login" shells. In other words, only when you log in to the system. Therefore it does not make sense to set aliases there.

Keep only environment variables (export commands) in .bash_profile. Use ~/.bashrc for everything else. Source it from .bash_profile too.

Solution 4:

I was thinking on .bash_profile then I forgot to login and doesn't work, if you login your .bash_profile will work perfectly.

Try:

$ login
$ login: (your name here)
$ password: (your password here)