.bash_profile not being read

So I am using CentOS 6.3 a fresh install and I was trying to add things to my path for OpenMPI so I edited my .bash_profile file to read:

FOO='test'
export FOO

# Add support for MPI
PATH=$PATH:/usr/lib64/openmpi/bin

# User specific environment and startup programs

PATH=$PATH:$HOME/bin




export PATH

Which apparently isn't being read when I start up a bash shell, my $PATH is without the /usr/lib64/openmpi/bin path and FOO doesn't exist when I try to echo $FOO

.bashrc is read just fine and if I do source ~/.bash_profile FOO is created as well as my $PATH being edited properly but it will not run .bash_profile on its own so if I could get any help that would be great.


Solution 1:

Could you describe how do you test these 2 files? Did you try login or non-login shell? Here is the difference:

When you login your system and see the command line prompt, it’s a login shell, and it executes these files in order:

/etc/profile
~/.bash_profile
~/.bashrc
/etc/bashrc

A non-login shell will only execute the two files in order:

/etc/bashrc
~/.bashrc

If you just simply start a bash shell by "bash", it is a non-login shell and ~/.bash_profile will not be invoked. If you expect the variables to be set even when running non-login shell, you should put them into ~/.bashrc.

Solution 2:

This is normal, .bash_profile is sourced for login shells, .bashrc is sourced for interactive non-login shells. In CentOS the top of .bash_profile usually has:

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

So you can put things in .bashrc.

Mac OS X Terminal reads .bash_profile when you open a new windows. gnome-terminal can be made to do that with Run command as a login shell.