
About .bashrc, .profile, .bash_profile and .bash_login
How it works
There are various files that may be executed by the Bash shell when it is started. Usually they follow this logic:
- When bash is invoked as an interactive login shell:
- Bash first reads and executes commands from the file
/etc/profile
, if that file exists. - After reading that file, it looks for
~/.bash_profile
,~/.bash_login
, and~/.profile
, in that order, and reads and executes commands from the first one that exists and is readable. Usually there is a default~/.profile
file, and~/.bash_profile
and~/.bash_login
usually do not exist.
- Bash first reads and executes commands from the file
- When bash is invoked as an interactive non-login shell:
- Bash reads and executes commands from
/etc/bash.bashrc
and~/.bashrc
, if these files exist. - The standard
~/.profile
sources (runs)~/.bashrc
if it exists.
- Bash reads and executes commands from
A login shell means a session where you directly log into a system, e.g. setting up a remote SSH session or logging in through a non-graphical text terminal. A non-login shell is then the type of shells you open after logging in: typically in a graphical session when you open a new terminal window.
The bottom line is that you should put customisations that should always be executed in ~/.bashrc!
Example
Example: After installing…