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
Top answer
1 of 7
72

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.

2 of 7
48

That's simple. It's explained in man bash:

/bin/bash
       The bash executable
/etc/profile
       The systemwide initialization file, executed for login shells
~/.bash_profile
       The personal initialization file, executed for login shells
~/.bashrc
       The individual per-interactive-shell startup file
~/.bash_logout
       The individual login shell cleanup file, executed when a login shell exits
~/.inputrc
       Individual readline initialization file

Login shells are the ones that are read one you login (so, they are not executed when merely starting up xterm, for example). There are other ways to login. For example using an X display manager. Those have other ways to read and export environment variables at login time.

Also read the INVOCATION chapter in the manual. It says "The following paragraphs describe how bash executes its startup files.", i think that's a spot-on :) It explains what an "interactive" shell is too.

Bash does not know about .environment. I suspect that's a file of your distribution, to set environment variables independent of the shell that you drive.

🌐
Linuxize
linuxize.com › post › bashrc-vs-bash-profile
.bashrc vs .bash_profile | Linuxize
May 10, 2020 - When invoked, Bash reads and executes commands from from a set of startup files. .bash_profile is read and executed when Bash is invoked as an interactive login shell, while .bashrc is executed for interactive non-login shell.
Discussions

terminal - What is the difference between .bash_profile and .bashrc? - Ask Different
To make an alias for the Terminal in OS X, you can either put the aliases in .bash_profile or .bashrc. What is the difference between the two and why would I choose to put aliases in one and not the More on apple.stackexchange.com
🌐 apple.stackexchange.com
May 10, 2012
bash_profile or bashrc??
.bash_profile is read and executed when Bash is invoked as an interactive login shell, while .bashrc is executed for an interactive non-login shell. Basically, use .bash_profile for things that should run just once after login (there is not much sense setting PATH each time you open the new shell, for example, as it will be inerited anyway). .bashrc for things you want to start always. More on reddit.com
🌐 r/linux4noobs
4
4
March 4, 2022
login - Why have both .bash_profile and .bashrc? - Unix & Linux Stack Exchange
What is the point of having both .bash_profile and .bashrc, with the former typically sourcing the latter, which in turn sources /etc/bashrc upon login? What would be the downside of putting all th... More on unix.stackexchange.com
🌐 unix.stackexchange.com
February 20, 2017
bash_profile or bashrc?? : linux4noobs
What is the difference between bash_profile and bashrc environment variables? More on old.reddit.com
🌐 r/linux4noobs
🌐
Baeldung
baeldung.com › home › scripting › difference between .bashrc, .bash-profile, and .profile
Difference Between .bashrc, .bash-profile, and .profile | Baeldung on Linux
March 18, 2024 - On every interactive login, the Bash shell executes .bash_profile. If .bash_profile is not found in the home directory, Bash executes the first readable file found from .bash_login and .profile. Whereas, on every interactive non-login shell startup, Bash executes .bashrc.
🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › bashrc vs. bash_profile: what is the difference?
bashrc vs. bash_profile: What Is the Difference? | phoenixNAP KB
January 23, 2023 - After, the shell searches for the ~/.bashrc configuration file for the specific user. The .bash_profile file is a hidden script file with custom configurations for a user terminal session.
🌐
TutorialsPoint
tutorialspoint.com › bashrc-vs-bash-profile-what-is-difference
bashrc vs. bash_profile What Is Difference
April 11, 2023 - Bashrc is used to customize your shell environment for each individual terminal window. This means that any changes you make to bashrc will affect only current terminal window. On other hand, bash_profile is used to set environment variables that are needed for entire session.
🌐
RedSwitches
redswitches.com › home › operating systems › the major differences between bashrc vs bash_profile in linux
Difference Between Bashrc Vs Bash_profile In Linux
September 10, 2025 - The bashrc file is often used to customize the behavior of the shell prompt and to define settings for non-login, non-interactive shells. Conversely, the bash_profile file is commonly used to set environment variables and execute shell commands ...
Find elsewhere
🌐
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 ...
🌐
Slashroot
slashroot.in › difference-between-bashrc-and-bashprofile
Difference Between .bashrc and .bash_profile
May 1, 2018 - It searches for a file named .bashrc (under the home directory of the user), and if found, it executes it. Two different files because they serve different purposes. Things that are specific to your login session should go inside .bash_profile.
🌐
GeeksforGeeks
geeksforgeeks.org › linux-unix › bashrc-vs-bash_profile-what-is-the-difference
bashrc vs. bash_profile: What Is the Difference? - GeeksforGeeks
January 29, 2024 - The ".bashrc" and ".bash_profile" ... While ".bashrc" is focused on customizing the terminal environment for each session, "bash_profile" is dedicated to tasks that should run only once during the login process....
🌐
Namehero
namehero.com › blog › bashrc-vs-bash_profile-a-complete-guide
Bashrc vs. bash_profile: A Complete Guide
February 19, 2025 - The only drawback of making edits to .bash_profile is that edits will only effect your login shell and not any subshells created during a session. Both .bashrc and .bash_profile are bash startup files used for configuring our shell environments.
Top answer
1 of 4
272

.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.

2 of 4
133

.profile

.profile is for things that are not specifically related to Bash, like environment variables PATH and friends, and should be available anytime.

For example, .profile should also be loaded when starting a graphical desktop session.

.bashrc

.bashrc is for the configuration of the interactive Bash usage, like Bash aliases, setting your favorite editor, setting the Bash prompt, etc.

.bash_profile

.bash_profile is for making sure that both the things in .profile and .bashrc are loaded for login shells.

For example, .bash_profile could be something simple like

. ~/.profile
. ~/.bashrc

If you were to omit .bashrc, only .profile would be loaded.

🌐
Lei Mao's Log Book
leimao.github.io › blog › bashrc-VS-profile-VS-bash_profile
~/.bashrc VS ~/.profile VS ~/.bash_profile - Lei Mao's Log Book
October 26, 2020 - However, if ~/.bash_profile or ~/.bash_login exists, ~/.profile will not be executed. The default content of the ~/.profile is simple. In most cases, it inherits whatever is in the ~/.bashrc, and adds some user specific executable filepath to the environment variable PATH.
Top answer
1 of 6
298

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.

2 of 6
73

Over the last few years, I've had a lot of time to waste, so I have researched this for a bit more than just 10 minutes. I have no idea if this is the best layout, it's just one that happens to work correctly in pretty much all cases.

The requirements:

  • ~/.profile must be compatible with any /bin/sh – this includes bash, dash, ksh, whatever else a distro might choose to use.

  • Environment variables must be put in a file that is read by both console logins (i.e. a 'login' shell) and graphical logins (i.e. display managers like GDM, LightDM, or LXDM).

  • There is very little point in having both ~/.profile and ~/.bash_profile. If the latter is missing, bash will happily use the former, and any bash-specific lines can be guarded with a check for $BASH or $BASH_VERSION.

  • The separation between *profile and *rc is that the former is used for 'login' shells, and the latter every time you open a terminal window. However, bash in 'login' mode doesn't source ~/.bashrc, therefore ~/.profile needs to do it manually.

The simplest configuration would be:

  • Have a ~/.profile that sets all environment variables (except bash-specific ones), perhaps prints a line or two, then sources ~/.bashrc if being run by bash, sticking to sh-compatible syntax otherwise.

    export TZ="Europe/Paris"
    export EDITOR="vim"
    if [ "$BASH" ]; then
        . ~/.bashrc
    fi
    uptime
    
  • Have a ~/.bashrc that performs any shell-specific setup, guarded with a check for interactive mode to avoid breaking things like sftp on Debian (where bash is compiled with the option to load ~/.bashrc even for non-interactive shells):

    [[ $- == *i* ]] || return 0
    
    PS1='\h \w \$ '
    
    start() { sudo service "$1" start; }
    

However, there's also the problem that certain non-interactive commands (e.g. ssh <host> ls) skip ~/.profile, but environment variables would be very useful to them.

  • Certain distributions (e.g. Debian) compile their bash with the option to source ~/.bashrc for such non-interactive logins. In this case, I've found it useful to move all environment variables (the export ... lines) to a separate file, ~/.environ, and to source it from both .profile and .bashrc, with a guard to avoid doing it twice:

    if ! [ "$PREFIX" ]; then   # or $EDITOR, or $TZ, or ...
        . ~/.environ           # generally any variable that .environ itself would set
    fi
    
  • Unfortunately, for other distributions (e.g. Arch), I haven't found a very good solution. One possibility is to use the (enabled by default) pam_env PAM module, by putting the following in ~/.pam_environment:

    BASH_ENV=./.environ        # not a typo; it needs to be a path, but ~ won't work
    

    Then, of course, updating ~/.environ to unset BASH_ENV.


Conclusion? Shells are a pain. Environment variables are a pain. Distribution-specific compile-time options are an immense pain in the ass.

🌐
Vegastack
vegastack.com › tutorials › bashrc-vs-bash-profile
.bashrc vs .bash_profile
October 19, 2023 - You can generate a startup file if one does not exist on your system. No, they serve different purposes. .bashrc is sourced for each new interactive shell, while .bash_profile is sourced only for login shells.
Top answer
1 of 3
62

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.

2 of 3
23

~/.profile is only called when you first log into your account. Any changes you make after that it would be wise to log out and back in so settings take effect. ~/.bashrc is called every time you launch a terminal window. There is another profile file and it is in the /etc/ directory. The main difference between the two is that the /etc/profile is called when anyone logs into the system, and the ~/.profile is called when only the user logs in.

If your export lines are only used in a terminal session then I would add them to the ~/.bashrc file as they are only valid during the terminal (bash) session. But, if you want them to be there with or without a terminal open, add them to the ~/.profile file, but like @chepner has stated do not put bash specific commands in the ~/.profile file.

If you screw up these files, there are default files stored in the /etc/skel/ directory that you can copy back over to your home directory. Also, the /etc/skel/ files are also used when you boot to a LiveUSB/CD/DVD, so if you modify those on your live media and then when it completes the boot you can have your own variables set.

🌐
Bhavith C
bhavithc.com › posts › bashrc-vs-bash-profile
.bashrc Vs .bash_profile | Bhavith C
May 17, 2022 - Each Unix like operating system have their own conventions, some OS use .profile ** instead of **.bash_profile · If your shell is bash then you have .bashrc, similarly if you using zsh then rc file will be .zshrc. Even vim and other applications like task uses same method to give user the flexibility to do some initialization stuff.
Top answer
1 of 1
11

Only .bashrc is run on non-login shells, while only .bash_profile is run on login shells.

.bashrc should typically contain things you want to set in every shell you open, like aliases, functions, etc. These are per shell session items that are not inherited from environment.

.bash_profile should contain things that need to be defined at login time only, like PATH and other environment variables, startup programs, etc. You just need things once, not in every shell you open. In most cases, you also need the things from .bashrc in your login shell. That's why .bash_profile sources .bashrc as well, but .bashrc doesn't usually source .bash_profile.

/etc/bashrc and /etc/profile are system wide settings made by the sys admin or the package manager. /etc/profile is sourced automatically in each login shell, before ~/.bash_profile. /etc/bashrc is not sourced, so it needs to be sourced from ~/.bashrc when required.

Now, you can club the two into a single file and link the other file to the first one. But you have to make sure that PATH and other variables are not relative defined (like PATH=$HOME/bin:$PATH) otherwise they will just keep becoming needlessly bigger. Also, you have to be careful of starting programs repeatedly. It's just easier to have these two separate.

Relevant section from the bash man page:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it 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. The --noprofile option may be used when the shell is started to inhibit this behavior.

When a login shell exits, bash reads and executes commands from the file ~/.bash_logout, if it exists.

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.