'Load .bash_profile for every terminal

I set up some aliases in my .bash_profile on my Max OS X. It works but when I'm opening a new tab I always have to load my .bash_profile file with this command:

source ~/.bash_profile

How can I make it work for every terminal I'm opening, even if I'm restarting my Mac or Linux computer?



Solution 1:[1]

If you use zsh , you can add source ~/.bash_profile line at the end of .zshrc file at the following path: /Users/YOUR USER NAME/.zshrc , then restart your Terminal/iTerm2 app.

Note that this file is hidden. You can press CMD + SHIFT + . in Finder to see it, Or just open it in default text editor with the following command from terminal:
open ~/.zshrc

Solution 2:[2]

I know this is a pretty old post, but this problem comes and goes quite oftenly and a lot of laborous solutions are offered. The fact is: being aware of a simple info would solve this pretty fast and easy:

LINUX/Unix OS will load the profile files on startup following the rules below (some distros may have other files names, mainly for user local profiles, but the main rule follows this):

  1. Login Shell

First and foremost: /etc/profile is loaded (global settings); Next: ˜/.bash_profile (local user settings- other files may be found, like ˜/.profile, depending on the distro. Check documentation).

So, if you are in a Login Shell environment, put all your crazy stuff inside ˜/.bash_profile (or the file provided by your distro) and everything will be fine.

  1. Non-login Shell

First and foremost: /etc/bashrc (some distros will load bash.bashrc); The next file to be seeked and loaded is ˜/.bashrc

And that's why so many people (just like me) got frustrated having to source their ˜/.bash_profile every single time a Terminal was loaded. We were simply inserting info in the "wrong" file- regarding the kind of shell loaded (see above: login, non-login).

More details on variants of the files mentioned above and some info on login vs non-login shell can be found here.

Hope it helps \o/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 jaymzleutz