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
bash_profile or bashrc?? : linux4noobs
What is the difference between bash_profile and bashrc environment variables? More on old.reddit.com
🌐 r/linux4noobs
Help me understand .profile vs .bash_profile vs .bashrc
profile files are used for "login shells" which are the kinds of shells you get when boot up a computer (without a login manager) and login but you can also configure other terminal applications to run the shell as a login shell. bashrc should be the standard place to put all your configuration. If you want to unify the login and interactive shells, you put a line like source ~/.bashrc at the end of your .bash_profile file. More info here . More on reddit.com
🌐 r/linux4noobs
2
3
May 7, 2019
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.

🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › bashrc vs. bash_profile: what is the difference?
bashrc vs. bash_profile: What Is the Difference? | phoenixNAP KB
December 16, 2025 - 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.
🌐
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....
Find elsewhere
Top answer
1 of 2
59

Bash aliases should go in the .bash_aliases or .bashrc files in individual home directories. If you must create global bash aliases, they can go in /etc/bash.bashrc, but it is often best simply to add them to the .bash_aliases or .bashrc files in /etc/skel so they are inherited by newly created users.

It is virtually always wrong to define an alias in in .profile, .bash_profile, or /etc/profile.

To understand why, one must understand under what circumstances commands from each of these files are run. There are misconceptions about this, which I address below.

Even though you want to define aliases for multiple users, you should be familiar with how they are defined for individual users, so that you can decide on the best method of doing what you need.

Aliases for Individual Users

Especially if you use a GUI, most of your interactive shells are probably non-login shells. Even if you never use a GUI, you probably still use non-login shells with some frequency. You'll want your aliases to work in these shells.

Especially if you ever log in non-graphically in a virtual console or via SSH, you probably use login shells some of the time. So you'll want your aliases to work in interactive login shells also.

When an interactive, non-login shell starts, it sources .bashrc in the user's home directory. By default in Ubuntu, each user's .bashrc itself sources .bash_aliases, if it exists.

  • To source a file is to cause its contents to be run in the current shell. Changes to the shell environment made in a file that is sourced persist even after all the commands in the file have been run.

Reading the comments in Ubuntu's default .bashrc reveals that it is officially intended that aliases go in .bashrc or .bash_aliases. .bashrc already contains some alias definitions (run grep '^[[:blank:]]*alias' ~/.bashrc to see them), and gives explicit advice about where to put new such definitions:

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

But what about interactive login shells? Instead of .bashrc, login shells source .profile.

  • ...Unless .bash_login exists, then it gets sourced instead.
  • ...Unless .bash_profile exists, then it gets sourced instead.

However, the good news is that by default in Ubuntu, commands in .bashrc will also run in interactive login shells because the default .profile checks if the current shell is bash (and if .bashrc exists), and if so, sources .bashrc:

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

I suggest users define new bash aliases in .bash_aliases in their home directories (creating it if it doesn't already exist). This is a particularly clean and simple way to make alias definitions permanent at the per-user level.

Aliases should not be defined in .profile because they would remain undefined in non-login shells. Unlike much of a bash shell's environment, aliases are not exported to child shells:

ek@Io:~$ alias hi='echo "Greetings, $USER!"'
ek@Io:~$ hi
Greetings, ek!
ek@Io:~$ bash
ek@Io:~$ hi
hi: command not found

In particular, by default most desktop environments cause .profile to be sourced on graphical login, but:

  1. This is not necessarily done by a bash shell, so alias definitions may not even be processed, and more importantly
  2. even if alias definitions are processed, they are not passed on to child processes. Particularly, they are not passed on to shells created by opening a Terminal window!

Aliases should not be defined in .bash_profile (or .bash_login) for the very same reason, but also for another reason. Naively creating one of these files and putting just alias definitions in it prevents any of the code in .profile from running!

In situations where .bash_profile or .bash_login really is useful, typically one sources .profile somewhere in them, which solves that problem. (Then the only remaining problem is that, like with .profile, defining aliases in .bash_profile or .bash_login doesn't work right.)

Aliases for New Individual Users, Automatically

When a user account of the type intended to represent a real human being is created, a new directory is typically made to serve as their home directory. The contents of /etc/skel are then copied to their home directory. This is how multiple users start out with some similar configuration files in their home directories. In Ubuntu, this includes .profile, .bashrc, and some other files.

To change what aliases are defined for new users, you can simply put them in /etc/skel/.bash_aliases (you will have to create it) or /etc/skel/.bashrc.

If you edit an already-existing file in /etc/skel you may want to back it up first--but you shouldn't put the backup in /etc/skel, or it, too, will be copied into new users' home directories.

This is likely the best way for you to add new aliases for multiple users. Existing users can simply add the aliases themselves. If you define the aliases in /etc/skel/.bash_aliases, you can simply direct them to that file, which they may choose to copy into their home directories (or add into their own custom .bash_aliases file).

It's trivial for a user to undefine an alias. Additionally, aliases are not extremely robust; they work only in particular circumstances. If you need to create a new command that works all the time, for everyone, you should not implement that command as an alias. And you cannot successfully force aliases on users who don't want them--they can simply unalias them.

Global Aliases, for All Users

Though I advise you to avoid this approach, you can define aliases in the the global /etc/bash.bashrc file. They will then be defined both for interactive non-login shells and for interactive login shells. The reason is, before any of the files in the user's home directory are sourced:

  • Login shells (and only login shells and other processes behaving like login shells) run commands from /etc/profile automatically.
  • Only non-login shells run commands in /etc/bash.bashrc automatically, but
  • Ubuntu's default /etc/profile checks if the running shell is bash (and if /etc/bash.bashrc exists) and, if so, sources /etc/bash.bashrc.

This is analogous to how the default per-user .profile sources the per-user .bashrc if the shell is bash (as detailed above).

Here's what the actual code for this looks like in the default /etc/profile:

if [ "$PS1" ]; then
  if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

That block also performs other tasks. Specifically, the outer if checks if the shell is likely to be interactive (by checking that the prompt text is non-empty), then checks if the current shell is bash and sources /etc/bash.bashrc if it is, and if not does some work that, for bash, is already done in /etc/bash.bashrc.

You should not define global aliases in /etc/profile for the same reason users should not define them in their local .profiles: if you do, they will be defined only for login shells, and not for their child shells.

Finally, note that, unlike the default per-user .bashrc, the default /etc/bash.bashrc file does not contain anything about aliases. It is somewhat unusual to give users aliases in a file where they cannot edit or disable them. (Of course, they still can do that, by overriding their definitions in their own local .bashrc, .bash_aliases, or elsewhere.)

Further Reading

  • Why is /etc/profile not invoked for non-login shells?
  • How to create a permanent “alias”?
  • How do I create a permanent Bash alias?
  • Why must I do . .bash_profile every time I create a new alias?
2 of 2
5

Here's some nice reading on it. ".bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells"

So for your alias, use .bash_profile

Top answer
1 of 3
66

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
24

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

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

🌐
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.
🌐
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.
🌐
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.
🌐
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.
🌐
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.
🌐
Linux Today
linuxtoday.com › home › blog
Understanding the Difference Between bashrc and bash_profile
May 9, 2025 - Two critical files for Bash users are bashrc and bash_profile.