The main difference with shell config files is that some are only read by "login" shells (eg. when you login from another host, or login at the text console of a local unix machine). these are the ones called, say, .login or .profile or .zlogin (depending on which shell you're using).

Then you have config files that are read by "interactive" shells (as in, ones connected to a terminal (or pseudo-terminal in the case of, say, a terminal emulator running under a windowing system). these are the ones with names like .bashrc, .tcshrc, .zshrc, etc.

bash complicates this in that .bashrc is only read by a shell that's both interactive and non-login, so you'll find most people end up telling their .bash_profile to also read .bashrc with something like

[[ -r ~/.bashrc ]] && . ~/.bashrc

Other shells behave differently - eg with zsh, .zshrc is always read for an interactive shell, whether it's a login one or not.

The manual page for bash explains the circumstances under which each file is read. Yes, behaviour is generally consistent between machines.

.profile is simply the login script filename originally used by /bin/sh. bash, being generally backwards-compatible with /bin/sh, will read .profile if one exists.

Answer from Cos on Stack Overflow
🌐
Stack Overflow
stackoverflow.com › questions › 415403 › whats-the-difference-between-bashrc-bash-profile-and-environment
shell - What's the difference between .bashrc, .bash_profile, and .environment? - Stack Overflow

The main difference with shell config files is that some are only read by "login" shells (eg. when you login from another host, or login at the text console of a local unix machine). these are the ones called, say, .login or .profile or .zlogin (depending on which shell you're using).

Then you have config files that are read by "interactive" shells (as in, ones connected to a terminal (or pseudo-terminal in the case of, say, a terminal emulator running under a windowing system). these are the ones with names like .bashrc, .tcshrc, .zshrc, etc.

bash complicates this in that .bashrc is only read by a shell that's both interactive and non-login, so you'll find most people end up telling their .bash_profile to also read .bashrc with something like

[[ -r ~/.bashrc ]] && . ~/.bashrc

Other shells behave differently - eg with zsh, .zshrc is always read for an interactive shell, whether it's a login one or not.

The manual page for bash explains the circumstances under which each file is read. Yes, behaviour is generally consistent between machines.

.profile is simply the login script filename originally used by /bin/sh. bash, being generally backwards-compatible with /bin/sh, will read .profile if one exists.

Answer from Cos on stackoverflow.com
🌐
Linuxize
linuxize.com › post › bashrc-vs-bash-profile
.bashrc vs .bash_profile | Linuxize
May 10, 2020 - Use .bash_profile to run commands that should run only once, such as customizing the $PATH environment variable . Put the commands that should run every time you launch a new shell in the .bashrc file.
Discussions

bash - When should I use .bashrc and when .profile? - Unix & Linux Stack Exchange

🌐 unix.stackexchange.com
October 19, 2018
I am basically putting all my settings into my .bashrc and when I was using zsh it was all in my .zshrc. The Rust installer just informed me that it has added the new installation to my PATH by More on unix.stackexchange.com

bash_profile or bashrc?? : linux4noobs

🌐 r/linux4noobs
What is the difference between bash_profile and bashrc environment variables? More on old.reddit.com

ELI5 - Ubuntu - .bashrc, .profile, .bash_profile : I'm not getting where I'm meant to add what to when where - I want to create a custom command based on a Python script I wrote : linux4noobs

🌐 r/linux4noobs
How do, there's a lot of stuff about these but I can't quite seem to grasp what they're saying! Basically I have a script that I've written, and... More on old.reddit.com

bash_profile or bashrc?? : r/linux4noobs

🌐 r/linux4noobs
What is the difference between bash_profile and bashrc environment variables? Share · Share · New to Reddit? Create your account and connect with a world of communities. Continue with Email · Continue With Phone Number · By continuing, you agree to our User Agreement and acknowledge that ... More on reddit.com
Videos
August 22, 2018
1.77K
🌐
Stack Exchange
apple.stackexchange.com › questions › 51036 › what-is-the-difference-between-bash-profile-and-bashrc
terminal - What is the difference between .bash_profile and .bashrc? - Ask Different

.bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.

When you login (type username and password) via console, either sitting at the machine, or remotely via ssh: .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. .bashrc is also run when you start a new bash instance by typing /bin/bash in a terminal.

On OS X, Terminal by default runs a login shell every time, so this is a little different to most other systems, but you can configure that in the preferences.

Answer from Alex on apple.stackexchange.com
🌐
RedSwitches
redswitches.com › home › operating systems › the major differences between bashrc vs bash_profile in linux
Difference Between Bashrc Vs Bash_profile In Linux
February 27, 2025 - Some everyday use cases for .bashrc ... other preferences for an individual’s interactive shell experience. The .bash_profile file is often used for configurations related to the login process....
🌐
Super User
superuser.com › questions › 789448 › choosing-between-bashrc-profile-bash-profile-etc
unix - Choosing between .bashrc, .profile, .bash_profile, etc - Super User

TL;DR:

  • ~/.bash_profile should be super-simple and just load .profile and .bashrc (in that order)

  • ~/.profile has the stuff NOT specifically related to bash, such as environment variables (PATH and friends)

  • ~/.bashrc has anything you'd want at an interactive command line. Command prompt, EDITOR variable, bash aliases for my use

A few other notes:

  • Anything that should be available to graphical applications OR to sh (or bash invoked as sh) MUST be in ~/.profile

  • ~/.bashrc must not output anything

  • Anything that should be available only to login shells should go in ~/.profile

  • Ensure that ~/.bash_login does not exist.

Answer from Dan Rabinowitz on superuser.com
Find elsewhere
🌐
Reddit
reddit.com › r › linux4noobs › comments › t6w9mh › bash_profile_or_bashrc
bash_profile or bashrc?? : r/linux4noobs
What is the difference between bash_profile and bashrc environment variables? Share · Share · New to Reddit? Create your account and connect with a world of communities. Continue with Email · Continue With Phone Number · By continuing, you agree to our User Agreement and acknowledge that ...
🌐
Ask Ubuntu
askubuntu.com › questions › 1411833 › what-goes-in-profile-and-bashrc
What goes in ~/.profile and ~/.bashrc? - Ask Ubuntu

It helps to understand which files get sourced, when, and why.

  • .profile is sourced by a login shell on startup. Typically, the only login shell you start is the one started when you log in, but you can run a login shell at any time with bash -l. (Also, on macOS, there is no initial login shell, so terminal emulators tend to run a login shell for each new window.)

  • .profile is an ideal place to set environment variables that can be inherited by any program started from the login shell.

  • .bashrc, on the other hand, is sourced by non-login interactive shells, such as those started by terminal windows (most configs also source .bashrc in interactive login shells though). This is where you set things specific to your interactive shell that aren't otherwise inherited from the parent process. For example, PS1 is set here because only interactive shells care about its value, and any interactive shell will source .bashrc anyway, so there is no need to define and export PS1 from .profile.

  • And though you didn't ask, it's worth pointing out the difference between .profile and .bash_profile here. .profile is "shared" by all POSIX shells (such as dash), so don't put anything bash-specific here. .bash_profile, though, is only used by bash, so you can use bash extensions in it. If .bash_profile is present, .profile will be ignored, so if for whatever reason you want to use both, you can add . ~/.profile to the top of your .bash_profile.

Answer from chepner on askubuntu.com
🌐
GeeksforGeeks
geeksforgeeks.org › bashrc-vs-bash_profile-what-is-the-difference
bashrc vs. bash_profile: What Is the Difference? | GeeksforGeeks
January 29, 2024 - Let’s clarify that the “.bashrc” and “.bash_profile” files are exclusive to Unix-based operating systems such as Linux and macOS. If you are using the Windows operating system, you won’t find these files on your system. In Linux or macOS, they are located in the “/home/yourusername” ...
🌐
Joshstaiger
joshstaiger.org › archives › 2005 › 07 › bash_profile_vs.html
.bash_profile vs .bashrc | Josh Staiger ☙
When you login (type username and password) via console, either sitting at the machine, or remotely via ssh: .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) inside Gnome ...
🌐
Namehero
namehero.com › blog › bashrc-vs-bash_profile-a-complete-guide
Bashrc vs. bash_profile: A Complete Guide
February 19, 2025 - Learn the difference between bashrc vs. bash_profile and how you can use these different commands in the Linux command line.
🌐
Tutorialspoint
tutorialspoint.com › home › articles on trending technologies › difference between .bashrc, .bash_profile, and .profile
Difference Between .bashrc, .bash_profile, and .profile
January 25, 2023 - Discover the distinctions between .bashrc, .bash_profile, and .profile to optimize your shell settings in Unix/Linux.
🌐
Iamsorush
iamsorush.com › posts › linux-bashrc-profile
What is the difference between .bashrc, .bash_profile, and .profile?
August 9, 2022 - The start-up Bash commands, variables, aliases and cutomizations are put in .bashrc, .bash_profile, and .profile files. So whenever you open a new terminal, one of these files is sourced first, but which one?
🌐
Server Fault
serverfault.com › questions › 261802 › what-are-the-functional-differences-between-profile-bash-profile-and-bashrc
linux - What are the functional differences between .profile .bash_profile and .bashrc - Server Fault

.bash_profile and .bashrc are specific to bash, whereas .profile is read by many shells in the absence of their own shell-specific config files. (.profile was used by the original Bourne shell.) .bash_profile or .profile is read by login shells, along with .bashrc; subshells read only .bashrc. (Between job control and modern windowing systems, .bashrc by itself doesn't get used much. If you use screen or tmux, screens/windows usually run subshells instead of login shells.)

The idea behind this was that one-time setup was done by .profile (or shell-specific version thereof), and per-shell stuff by .bashrc. For example, you generally only want to load environment variables once per session instead of getting them whacked any time you launch a subshell within a session, whereas you always want your aliases (which aren't propagated automatically like environment variables are).

Other notable shell config files:

/etc/bash_profile (fallback /etc/profile) is read before the user's .profile for system-wide configuration, and likewise /etc/bashrc in subshells (no fallback for this one). Many systems including Ubuntu also use an /etc/profile.d directory containing shell scriptlets, which are . (source)-ed from /etc/profile; the fragments here are per-shell, with *.sh applying to all Bourne/POSIX compatible shells and other extensions applying to that particular shell.

Answer from geekosaur on serverfault.com
🌐
Stack Exchange
unix.stackexchange.com › questions › 476593 › when-should-i-use-bashrc-and-when-profile
bash - When should I use .bashrc and when .profile? - Unix & Linux Stack Exchange

.profile is read by every login shell, .xxxrc is read by every interactive shell after reading .profile.

You need to decide yourself depending on what you like to add.

A good idea is to put everything that sets exported environment variables and thus propagates to sub shells into .profile.

Things that are not propagated should be in .bashrc or whatever your shell looks into. This is e.g. alias and function definitions.

Answer from schily on unix.stackexchange.com
🌐
Tutorialspoint
tutorialspoint.com › home › articles on trending technologies › difference between .bashrc and .bash_profile
Difference Between .bashrc and .bash_profile
April 11, 2023 - Discover the distinctions between .bashrc and .bash_profile for effective Linux shell configuration.
🌐
GitHub
gist.github.com › korya › bd0de47f36dbb5c29a90
.bashrc vs .bash_profile · GitHub
.bashrc vs .bash_profile. GitHub Gist: instantly share code, notes, and snippets.
🌐
Hacker News
news.ycombinator.com › item
/.bashrc VS –/.profile VS –/.bash_profile | Hacker News
October 24, 2020 - I get in theory why I'd want interactive login shells to have a fancier / more complex environment than others. Maybe I should care more about optimizing startup time of non-interactive shells. But really, who has the time to figure that stuff out · Put env vars in bash profile and functions, ...
🌐
Medium
medium.com › @shalinpatel. › difference-between-bashrc-bash-profile-and-profile-1947edea4318
Difference Between .bashrc, .bash-profile, and .profile | by Shalin Patel | Medium
January 5, 2024 - Bash shell uses a few startup files to set up the environment. These files determine certain Bash shell configurations for the shell itself and system users. In this tutorial, we’ll learn about a few…
🌐
YouTube
youtube.com › zach gollwitzer
The difference between .bashrc, .bash_profile, .profile, and .bash_login (login vs non login shells) - YouTube
10:28
See the corresponding blog post here - https://zachgoll.github.io/blog/2019/user-permissions/#bashrc-bash-profile-bash-login-profile 0:00 Intro 0:52 What is ...
Published: March 14, 2019
Views: 6K