~/.bashrc in Linux: shell configuration

Updated November 1, 2026

~/.bashrc is a script that bash runs when it starts an interactive non-login shell.

Common cases

echo 'export EDITOR=vim' >> ~/.bashrc   # add a setting
echo "alias ll='ls -lh'" >> ~/.bashrc    # add an alias
source ~/.bashrc                          # reload without restarting
cat ~/.bashrc                             # see what is inside

Sample output

$ echo 'export EDITOR=vim' >> ~/.bashrc
$ tail -2 ~/.bashrc
fi
export EDITOR=vim
$ echo $EDITOR

$ source ~/.bashrc
$ echo $EDITOR
vim

How it works: which file is read when

~/.bashrc is read for an interactive non-login shell (a new terminal window or tab). ~/.bash_profile (or ~/.profile) is read once at login. So aliases and the prompt go in .bashrc, while one-time things like starting an ssh agent go in .bash_profile. Changes take effect in new shells; to apply them in the current one, run source ~/.bashrc.

Common mistakes

A single > instead of >> wipes the file. The sandbox ~/.bashrc has 117 lines, and echo 'export EDITOR=vim' > ~/.bashrc leaves exactly one of them, along with the coloured output and aliases like ll. Nothing reports an error, and you notice the loss only in the next terminal. Check the result with tail -2 ~/.bashrc.

A PATH line that forgets the old value switches off every command at once. Append export PATH="$HOME/bin" with no :$PATH at the end, and a new shell answers bash: ls: command not found to ls /etc. The shell is still alive and full paths still work: /usr/bin/nano ~/.bashrc opens the file and lets you repair it. Keep the old window open until you have, its PATH is still intact.

A non-interactive shell does not read ~/.bashrc. bash -c 'echo $EDITOR' prints an empty line even though export EDITOR=vim is in the file, while bash -ic 'echo $EDITOR' prints vim. The Ubuntu version of ~/.bashrc also opens with the test case $- in *i*) ;; *) return;; esac, which stops reading the file in a non-interactive shell. That is why scripts and cron jobs see neither your aliases nor your PATH.

Used in

You need this in the lesson The shell environment. The theory is the chapter The shell environment and configuration.

See also

Aliases, Environment variables, The PATH variable.

Try it

Open the sandbox: a real throwaway Linux terminal in your browser. Run the commands above by hand - the container is deleted when you leave.