Monday, September 25, 2006

Ubuntu: .bash_profile does not get run at startup in Graphical Mode Login

I installed the Sun JDK on my computer and, set up the JAVA_HOME environment in .bash_profile file. Then, I sourced the file:
source .bash_profile
Fine, the JAVA_HOME variable was there I could do my work. However, once I rebooted my computer I could not get my env variable again when I opned gnome terminal. However, if I turn to console mode (Alt+Crtl+F2, for instance) I could get the variable.
This happens because Ubuntu does not "source" the file ~/.bash_profile during Graphical login. The script /etc/gdm/Xsession is in charge of initializing variables for use by all sessions. However, this script does not "source" the ~/.bash_profile file as an interactive Bash login would do. The solution therefore is to edit the /etc/gdm/Xsession file and add source .bash_profile. Here is a snipet:

sudo vi /etc/gdm/Xsession

# First read /etc/profile and .profile
test -f /etc/profile && . /etc/profile
test -f "$HOME/.bash_profile" && . "$HOME/.bash_profile"
# Second read /etc/xprofile and .xprofile for X specific setup
test -f /etc/xprofile && . /etc/xprofile
test -f "$HOME/.xprofile" && . "$HOME/.xprofile"

The page http://www.linuks.mine.nu/debian-faq-wiki/DotFiles gives an interesting explanation of the way your Debian/Ubuntu systems behave with respect to the reading of "dot files" at login time, setting up aliases, setting up environment variables, and so on is all highly dependent on how you actually log in. It's worth reading.

1 comment:

Unknown said...

Solution:
Edit your profile in the GNOME terminal and set: Run command as login shell