0

I've created some aliases in a bash_profile (followed this) but when I open a new Terminal i need to write source ~/.bash_profile to use them.

I'd like to use the aliases as soon as I opened new Terminal windows, what should I do?

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • The linked blog post has a section on how to make your aliases permanent ("Permanent Aliases"). Have you tried that? – Gino Mempin Apr 07 '18 at 11:50
  • There's also [this post](https://apple.stackexchange.com/questions/99688/how-to-persistently-define-aliases-in-terminal) on https://apple.stackexchange.com/. – Gino Mempin Apr 07 '18 at 11:51
  • maybe your system loads ~/.bashrc by default so you can try to put your aliases there – Aliaksandr Sushkevich Apr 07 '18 at 11:52
  • 1
    Possible duplicate of [Load .bash\_profile for every terminal](https://stackoverflow.com/questions/34352907/load-bash-profile-for-every-terminal) – tripleee Apr 07 '18 at 14:40
  • If this or any answer has solved your question please consider [accepting it](https://meta.stackexchange.com/q/5234/179419) by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – Benjamin Scholtz May 03 '18 at 14:24

1 Answers1

3

Josh Staiger gives a good summary in his blogpost ".bash_profile vs .bashrc", summarised below:

  • .bash_profile is executed when a user logs in via the console
  • .bashrc is executed whenever a logged in user opens a new terminal window

So if you'd like to use newly created aliases as soon as you open a new terminal window, the solution is to use .bashrc instead of .bash_profile for your aliases.

The blog post includes some more details about synchronising PATHs that you set in .bashrc for logged in and non logged in shells, that may or may not be relevant to your specific problem.

Benjamin Scholtz
  • 823
  • 6
  • 15
  • It depends on how your terminal emulator is configured. On macOS, for example, the default is usually to open a new login shell for each window, because the terminal emulator itself wasn't started from a login shell itself (at whatever remove). – chepner Apr 07 '18 at 15:40
  • 1
    Specifically, `.bash_profile` is executed for a login shell; `.bashrc` is executed for a nonlogin interactive shell. – chepner Apr 07 '18 at 15:41