Reputation: 5082
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?
Upvotes: 28
Views: 44483
Reputation: 2799
If you are using zsh, you can add source ~/.bash_profile
at the end of the .zshrc file located at the following path: /Users/YOUR USER NAME/.zshrc
After making this change, restart your Terminal or iTerm2 application.
Please note that the .zshrc file is hidden. To make it visible, you can press CMD + SHIFT + . in Finder. Alternatively, you can open it in the default text editor using the following command in the terminal:
open ~/.zshrc
Update
You don't need to perform these steps manually. You can run the following command instead:
echo "source ~/.bash_profile" >> ~/.zshrc
* Dont forget to restart your terminal.
Upvotes: 45
Reputation: 1
For Ubuntu system - Do it from Terminal > Preferences > Profile > Command > click on checkbox of Run command as a login shell and then reopen the Terminal
Upvotes: 0
Reputation: 165
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):
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.
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/
Upvotes: 2
Reputation:
The files executed at the start may be several, usually ~/.bashrc for interactive, non-login shells. The kind I assume you are using.
If so, create an ~/.bashrc
file and source ~/.bash_profile
in it:
if [ -f ~/.bash_profile ]; then
. ~/.bash_profile
fi
This web site has a lot of information about this.
Study this image, as it is a condensed guide
If you do need to find out exactly which file is being executed, take a look at this web page. It has a lot of specific tests to find out what file is setting what.
Specific for Mac-OS (which is an exception and loads ~/.bash_profile) do as is recomended in the site linked in this answer AFTER you confirm that your bash is doing as explained there.
Upvotes: 24