.bashrc vs .bash_profile: What is the Difference?

When you open a terminal or log in to a Linux system, Bash reads and executes commands from a set of startup files. These files let you customize your shell environment — creating aliases
, adding directories to $PATH
, setting environment variables
, and changing the shell prompt.
Which startup file Bash reads depends on whether the shell is a login or non-login shell. This guide explains the difference between .bashrc and .bash_profile, when each file is loaded, and where to put your customizations.
Interactive vs Non-Interactive Shells
A shell can be either interactive or non-interactive:
- Interactive shell — A shell that reads input from the user and writes output to the terminal. This is what you use when you type commands at a prompt.
- Non-interactive shell — A shell that runs without user interaction, such as when executing a Bash script
. Non-interactive shells do not read
.bashrcor.bash_profile.
Login vs Non-Login Shells
An interactive shell can be either a login or a non-login shell:
- Login shell — Invoked when you log in to the system. This includes logging in via SSH
, logging in at a local console, or starting Bash with the
--loginoption. - Non-login shell — Invoked when you open a new terminal window or tab in a graphical desktop, or when you type
bashinside an existing shell.
You can check whether your current shell is a login shell by running:
shopt login_shellIf the output is login_shell on, it is a login shell. If it is login_shell off, it is a non-login shell.
Startup File Loading Order
When Bash starts as an interactive login shell, it reads the following files in order:
/etc/profile— System-wide settings. This file usually sources scripts from/etc/profile.d/.~/.bash_profile— User-specific login settings. If this file does not exist, Bash looks for~/.bash_login, then~/.profile, and executes commands from the first one it finds.
When Bash starts as an interactive non-login shell, it reads only:
~/.bashrc— User-specific shell settings.
The following table summarizes which files are read in each scenario:
| Shell Type | Files Read |
|---|---|
Interactive login (SSH, console, bash --login) | /etc/profile → ~/.bash_profile (or ~/.bash_login or ~/.profile) |
Interactive non-login (new terminal tab, typing bash) | ~/.bashrc |
| Non-interactive (scripts) | None (unless BASH_ENV is set) |
Difference Between .bashrc and .bash_profile
.bash_profile is executed once when you log in. .bashrc is executed every time you open a new interactive shell.
In practice, most users want their customizations to be available in every shell — both login and non-login. The standard approach is to put all your customizations in ~/.bashrc and have ~/.bash_profile source it:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fiWith this setup, both login and non-login shells load the same configuration.
Where to Put What
| Customization | File | Reason |
|---|---|---|
| Aliases | ~/.bashrc | Available in every interactive shell |
| Shell functions | ~/.bashrc | Available in every interactive shell |
Prompt customization (PS1) | ~/.bashrc | Applied to every new shell |
$PATH modifications | ~/.bashrc | Loaded in every shell (when .bash_profile sources .bashrc) |
Environment variables (export) | ~/.bashrc | Available everywhere if sourced from .bash_profile |
| Commands to run once at login | ~/.bash_profile | Run only during login (e.g., ssh-agent, startup messages) |
.profile vs .bash_profile
Many Linux distributions use ~/.profile instead of ~/.bash_profile. The difference is:
~/.bash_profile— Read only by Bash.~/.profile— Read by Bash and other POSIX-compatible shells (sh, dash).
If both ~/.bash_profile and ~/.profile exist, Bash reads only ~/.bash_profile and ignores ~/.profile. If you want ~/.profile to be read, either remove ~/.bash_profile or source ~/.profile from within it.
Ubuntu and Debian create ~/.profile by default and do not create ~/.bash_profile. Fedora and RHEL create ~/.bash_profile.
macOS Note
On macOS, Terminal.app and iTerm2 open login shells by default, which is the opposite of most Linux terminal emulators. This means ~/.bash_profile (or ~/.zprofile for zsh) is read every time you open a terminal window on macOS.
Since macOS Catalina (2019), the default shell on macOS is zsh, not Bash. The zsh equivalents are:
| Bash File | Zsh Equivalent |
|---|---|
~/.bash_profile | ~/.zprofile |
~/.bashrc | ~/.zshrc |
If any of these startup files do not exist on your system, you can create them .
Quick Reference
| File | When Loaded | Use For |
|---|---|---|
/etc/profile | Login shells | System-wide environment settings |
~/.bash_profile | Login shells | User login settings, sourcing .bashrc |
~/.profile | Login shells (if no .bash_profile) | Portable user login settings |
~/.bashrc | Non-login interactive shells | Aliases, functions, prompt, PATH |
/etc/bash.bashrc (Debian/Ubuntu) or /etc/bashrc (Fedora/RHEL) | Non-login interactive shells | System-wide shell settings |
Troubleshooting
Aliases do not work when connecting via SSH
SSH opens a login shell, which reads ~/.bash_profile but not ~/.bashrc. Add . ~/.bashrc inside your ~/.bash_profile so that aliases are loaded in login shells as well.
PATH changes in .bashrc are not applied
Make sure ~/.bash_profile sources ~/.bashrc. Without this, login shells do not read ~/.bashrc and your PATH changes are ignored.
Changes to .bashrc do not take effect
After editing ~/.bashrc, either open a new terminal or run source ~/.bashrc to apply the changes in the current shell.
Both .bash_profile and .profile exist but only one is used
If ~/.bash_profile exists, Bash ignores ~/.profile. Either consolidate your settings into one file or have ~/.bash_profile source ~/.profile.
FAQ
Which file should I edit to add an alias?
Add aliases to ~/.bashrc. As long as ~/.bash_profile sources ~/.bashrc, your aliases will be available in both login and non-login shells.
Why does my terminal not read .bash_profile?
Most Linux terminal emulators (GNOME Terminal, Konsole, xfce4-terminal) open non-login shells, which read ~/.bashrc instead of ~/.bash_profile. Only SSH sessions, console logins, and bash --login trigger a login shell.
What is the difference between source and .?
They are equivalent. Both execute commands from a file in the current shell. . ~/.bashrc and source ~/.bashrc do the same thing. The . syntax is POSIX-compatible, while source is a Bash extension.
Does .bashrc run when I execute a script?
No. Scripts run in a non-interactive shell, which does not read ~/.bashrc unless the script explicitly sources it or the BASH_ENV variable is set to point to it.
Where should I put environment variables for GUI applications?
GUI applications do not read .bashrc or .bash_profile. On systemd-based systems, put environment variables in ~/.config/environment.d/*.conf or set them in your desktop environment settings.
Conclusion
.bash_profile is read by login shells and .bashrc is read by non-login interactive shells. The simplest setup is to put all your customizations in ~/.bashrc and have ~/.bash_profile source it. This way, your aliases, PATH, and environment variables are available in every interactive shell.
If you have any questions, feel free to leave a comment below.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page