Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

~/.profile, ~/.bashrc, and ~/.bash_profile not running on new terminal start up

Tags:

I am trying to create a permanent alias for my terminal. I put the alias in my ~/.profile, ~/.bashrc, and ~/.bash_profile files, previously empty. When I start a new terminal, bash does not recognize the alias, but if I source any of them, it does. Why are these not getting run when I open a terminal? I am on OSX.

like image 930
DazedAndConfused Avatar asked Jul 29 '14 22:07

DazedAndConfused


People also ask

Does bashrc or bash_profile run first?

bash_profile is executed to configure your shell before the initial command prompt. But, if you've already logged into your machine and open a new terminal window (xterm) then . bashrc is executed before the window command prompt. .

How do I run a .bashrc file?

So, every time you need to initiate the . bashrc File from the beginning, you can do so by pressing Ctrl+Alt+T or opening a new terminal tab, making it all more accessible. At each launch, Bash runs the contents of the . bashrc file to load your preferences.

How do I open a .bashrc file in terminal?

The quickest way to access it is nano ~/. bashrc from a terminal (replace nano with whatever you like to use). If this is not present in a user's home folder the system-wide . bashrc is used as a fallback as it is loaded before the user's file.

Where is the ~/ bashrc file?

In most cases, the bashrc is a hidden file that lives in your home directory, its path is ~/. bashrc or {USER}/. bashrc with {USER} being the login currently in use. The dot in front of the filename (.


2 Answers

Newer MacOS versions use zsh as the default shell for both Terminal and iTerm2. Run echo $SHELL to confirm if this is the case for you.

Zsh looks for a .zshrc file upon shell startup, so to continue using zsh while sourcing the contents of your bash profile, you can run the following:

echo "source ~/.bash_profile" >> ~/.zshrc 

Open a new terminal window for the changes to take effect.

like image 124
lchapo Avatar answered Oct 01 '22 14:10

lchapo


Two things need to happen here when using iTerm to get the loading of dotfiles to work.

First you should add the following to your .bash_profile

[[ -s ~/.bashrc ]] && source ~/.bashrc 

Secondly you will need to ensure that in iTerm preferences your terminal is set to launch a login shell.

iTerm Preferences

Hope this helps!

like image 38
ptierno Avatar answered Oct 01 '22 15:10

ptierno