Understanding .bashrc and .profile Load Order - When Settings Are Not Applied
Linny-senpai, My Settings Are Not Showing Up!
.bashrc but it's not working even after reopening the terminal....bashrc and .profile are each loaded, everything will click.This article answers these questions:
- What is the difference between
.bashrcand.profile? - Why don't my settings appear after editing
.bashrc? - Why are my aliases missing after an SSH connection?
- How can I reload settings without restarting the terminal?
The Role of .bashrc vs .profile
.bashrc and .profile look similar. Which one should I use?| File | When It Is Loaded |
|---|---|
~/.bashrc |
Interactive shell (when you open a normal terminal) |
~/.profile |
Login shell (when you connect via SSH or log in) |
~/.bash_profile |
Login shell (takes priority over ~/.profile) |
If ~/.bash_profile exists, ~/.profile is not loaded. Only one of them runs per login.
Understanding the Two Types of Shells
Login Shell
Started in these situations:
- Connecting to a server via SSH (
ssh user@host) - Switching to root with
sudo -i - Switching users with
su -
Files loaded:
/etc/profile~/.bash_profile(if it exists) or~/.profile
Interactive Non-Login Shell
Started in these situations:
- Opening a terminal app (GNOME Terminal, etc.) on the desktop
- Starting a new shell by typing
bash
Files loaded:
/etc/bash.bashrc~/.bashrc
Quick rule: Desktop terminal → ~/.bashrc. SSH connection → ~/.profile (or ~/.bash_profile).
The Full Load Order
.bashrc aliases are missing over SSH because the login shell never reads .bashrc?.bashrc is not loaded automatically.Login shell (SSH connection):
/etc/profile
└─ ~/.bash_profile (if it exists)
└─ ~/.bashrc (only if bash_profile explicitly calls it)
or
└─ ~/.profile (if bash_profile does not exist)
└─ ~/.bashrc (only if profile explicitly calls it)
Interactive shell (terminal launch):
/etc/bash.bashrc
└─ ~/.bashrc
A login shell does not automatically load ~/.bashrc.
To use your aliases and functions over SSH, you must explicitly call ~/.bashrc from inside ~/.bash_profile or ~/.profile.
Common Problems and How to Fix Them
Problem 1: Aliases Missing After SSH Login
.bashrc, but after SSH-ing in I get "command not found"!.bashrc. Add a snippet to .bash_profile to call .bashrc explicitly.Fix: Add the following to ~/.bash_profile (or ~/.profile if ~/.bash_profile doesn't exist):
# ~/.bash_profile
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fiUbuntu often includes this snippet in ~/.profile by default. Check first:
cat ~/.profile
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
If you see this output, your SSH sessions will already load ~/.bashrc.
Problem 2: Edited .bashrc but the Terminal Did Not Update
.bashrc and saved it, but my open terminal still can't use the new alias!source command reloads the file without restarting!Reload immediately with source:
source ~/.bashrc
Or the equivalent shorthand:
. ~/.bashrc
source (or .) runs the file inside the current shell, not in a subprocess. Changes take effect immediately — no terminal restart needed.
How to Check Your Current Shell Type
$0 variable — it tells you how Bash was invoked.echo $0
# Login shell: starts with a dash (-) -bash # Non-login shell: no leading dash bash
To trace which startup files are being sourced:
bash --login -x 2>&1 | head -30
Each sourced file appears prefixed with +.
What to Put Where
| Setting Type | Where to Write | Reason |
|---|---|---|
Aliases (alias ll='ls -la') |
~/.bashrc |
Only needed in interactive terminals |
| Shell functions | ~/.bashrc |
Same as above |
Environment variables (PATH) |
~/.profile |
Needed in login shells too |
Prompt settings (PS1) |
~/.bashrc |
Display settings belong in terminal config |
Writing PATH in ~/.bashrc often works day-to-day, but it won't be available to programs launched without a login shell (e.g., cron jobs). Put critical environment variables in ~/.profile to be safe.
Hands-On Practice
Step 1: Check your current shell type
echo $0
Step 2: Verify that ~/.profile sources .bashrc
grep -n "bashrc" ~/.profile
# Good output — .bashrc will be sourced on login 6: if [ -f "$HOME/.bashrc" ]; then 7: . "$HOME/.bashrc" 8: fi
Step 3: Add a test alias and reload instantly
# Append a test alias echo "alias hello='echo Hello Linux World!'" >> ~/.bashrc # Reload without restarting source ~/.bashrc # Verify hello
Hello Linux World!
Hint: if it still doesn't work
Check that the alias was actually appended:
tail -5 ~/.bashrc
If the alias is there but still fails, check for syntax errors in .bashrc:
bash -n ~/.bashrc
No output means no syntax errors.
Summary
Key Points to Remember
~/.bashrcis loaded when you open a terminal (interactive shell)~/.profileis loaded on SSH login or system login (login shell)~/.bash_profiletakes priority over~/.profilewhen both exist- To use
.bashrcsettings over SSH, call it from~/.profileor~/.bash_profile - To apply edits immediately, run
source ~/.bashrc(no restart needed)