As this post says, the ~/.bashrc is sourced automatically in Ubuntu 12.04 LTS Server, which I use. I don't know where he got this information from, but as it is not downvoted yet, I believe it is true.

I used this script to check if it is sourced:

if [ -f ~/.bashrc ]; then
   echo "Not sourced!";

Just for info: Permissions at the moment are 775 and owner is me.

So why is my ~/.bashrc not sourced?

  • that script is not going to tell you if a script is sourced, it is going to tell you if that file exists and is regular. – Jay _silly_evarlast_ Wren Feb 24 '13 at 15:25
  • Ok thank you @Jay_silly_evarlast_Wren How do I check if it is sourced then? – Peter Feb 24 '13 at 15:27
  • Do you have a .profile file in your home dir? ll ~/.profile That file calls the .bashrc (because it is autosourced, not the .bashrc): if [ -n "$BASH_VERSION" ]; then if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fi fi – antivirtel Feb 24 '13 at 15:27
  • Well, an easy test to determine whatever your ~/.bashrc is being sourced or not would be to set an alias or an environment variable in it. – andol Feb 24 '13 at 15:35
  • 1
    Thank you @B.Roland. You completely answered my question now. – Peter Feb 24 '13 at 15:49

As we found out, you have no .profile file in your home. Look at the bash's manual here for Bash startup files.

Make a .profile for yourself:

nano ~/.profile

Insert this text to that file (copied from Debian Squeeze):

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

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

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then

Tip: if you are making a new user, use the -m switch to make him a dir, and place the default files, eg.: sudo useradd example -m -d /home/example

|improve this answer|||||
  • Out of curiosity: What permissions do we need for .bashrc and .profile? And who got to be the owner and ownergroup? Thanks for posting the answer. – Peter Feb 24 '13 at 15:55
  • It is your own, so copy your homedir's permissions. Mine are different from the homedir's (755), the .bashrc's: 644... but it doesn't really matter, just need to be readable by you. – antivirtel Feb 24 '13 at 16:02
  • Otherwise you may have a .bash_logout file also: paste2.org/p/2970860 (you may tumb up my answer, it is used to do that's how here) – antivirtel Feb 24 '13 at 16:19
  • I would if I could! – Peter Feb 24 '13 at 16:21

You can see exactly what is executed by using bash verbose mode.

For a non-login shell:

$ bash -v 2>&1 | less

For a login shell:

$ bash -vl 2>&1 | less

I don't have a 12.04 system on hand to confirm that .bashrc is executed when using login shell. I'm fairly certain that it is. If it is not, I would guess that you, or whatever is invoking bash on your behalf, are not specifying a login shell. Examples of this is remote command execution via ssh.

ssh to get a shell spawns a login shell

$ ssh remotehost

ssh to invoke a remote command does not spawn a login shell

$ ssh remotehost remotecommand

Also see the bash man page --norc option which mentions that this option is on by default if bash is invoked as sh. This used to be important, but less so now that ubuntu has moved to dash for sh instead of bash.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.