I was always confused about where to put my config for the bash shell on Linux. I shoved everything into
~./bashrc because that seemed to be the easiest solution.
.bashrcis a shell script that Bash runs whenever it is started interactively. It initializes an interactive shell session. You can put any command in that file that you could type at the command prompt.
You put commands here to set up the shell for use in your particular environment, or to customize things to your preferences. A common thing to put in
.bashrcare aliases that you want to always be available.
Apparently, this is not recommended:
~/.profile is the place to put stuff that applies to your whole session, such as programs that you want to start when you log in (but not graphical programs, they go into a different file), and environment variable definitions.
~/.bashrcis the place to put stuff that applies only to bash itself, such as alias and function definitions, shell options, and prompt settings. (You could also put key bindings there, but for bash they normally go into
~/.bash_profilecan be used instead of
~/.profile,but it is read by bash only, not by any other shell. (This is mostly a concern if you want your initialization files to work on multiple machines and your login shell isn't bash on all of them.) This is a logical place to include
~/.bashrcif the shell is interactive.
Sometimes, you have to set a
PATH environment variable in your shell for some programs to work. And I've always put that into
bash.rc - mostly because tutorials or documentations for programs tell you to set the path variable there and I didn't know that it's not best practice.
~/.bash_rcis not read by any program, and
~/.bashrcis the configuration file of interactive instances of bash. You should not define environment variables in
~/.bashrc.The right place to define environment variables such as PATH is ~/.profile (or
~/.bash_profileif you don't care about shells other than bash).