~/.bash_profile
is only sourced by bash when started in login mode. That is typically when you log in at the console (Ctrl+Alt+F1..F6), connect via ssh, or use sudo -i
or su -
to run commands as another user.
When you log in graphically, ~/.profile
will be specifically sourced by the script that launches gnome-session (or whichever desktop environment you're using). So ~/.bash_profile
is not sourced at all when you log in graphically.
When you open a terminal, the terminal starts bash in (non-login) interactive mode, which means it will source ~/.bashrc
.
The right place for you to put these environment variables is in ~/.profile
, and the effect should be apparent next time you log in.
Sourcing ~/.bash_profile
from ~/.bashrc
is the wrong solution. It's supposed to be the other way around; ~/.bash_profile
should source ~/.bashrc
.
See DotFiles for a more thorough explanation, including some history of why it is like it is.
(On a side note, when installing openjdk via apt, symlinks should be set up by the package, so that you don't really need to set JAVA_HOME
or change PATH
)
Best Answer
It isn't necessarily run; at the top of the standard .bashrc is this comment:
I believe there is an option to run bash terminal as a login shell or not. With Ubuntu, gnome-terminal does not normally run as a login shell, so .bashrc should be run directly.
For login shells (like the virtual terminals), normally the file
~/.profile
is run, unless you have either~/.bash_profile
or~/.bash_login
, but they are not there by default. By default, Ubuntu uses only .profile.The standard
~/.profile
has this in it:This runs .bashrc if it is available - assuming $BASH_VERSION is present in your environment. You can check for this by entering the command
echo $BASH_VERSION
, and it should display some information on version number - it should not be blank.