11

I add $HOME/bin to $PATH from ~/.profile. However, it seems it is not sourced during login. I use a login manager - lxdm I think, and not startx. I know this matters as to which scripts are executed.

To illustrate, see how the $HOME/bin is added after I explicitly source ~/.profile. But shouldn't it have been sourced during the graphical login?

sashoalm@aspire:~$ echo $PATH 
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
sashoalm@aspire:~$ source ~/.profile 
sashoalm@aspire:~$ echo $PATH 
/home/sashoalm/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
sashoalm@aspire:~$ 
sashoalm
  • 5,820

4 Answers4

14

But shouldn't it have been sourced during the graphical login?

There's a minor debate about that on which some graphical logins take an unusual stance...

I add $HOME/bin to $PATH from ~/.profile. However, it seems it is not sourced during login. I use a login manager - lxdm I think

Correct. Most DM's do read ~/.profile when you log in. However, they must do this explicitly, since ~/.profile is traditionally sourced by login shells and a DM (GUI login) is not a shell!

Which is the justification I have seen from the lightdm people for not sourcing ~/.profile explicitly -- because a DM is not a shell.

You can source ~/.profile yourself from ~/.xsession -- see here.

goldilocks
  • 87,661
  • 30
  • 204
  • 262
  • 3
    Sourcing ~/.profile from ~/.xsession probably worked when this answer was written, but it doesn't seem to work anymore. I got it working by sourcing it in ~/.xsessionrc instead. – Filip S. Jul 17 '17 at 10:10
4

Agree with @goldilocks mostely. Just want to add that the script to source ~/.profile is ~/.xsessionrc, instead of ~/.xsession.

Here is the rationale:

qxu@debian:/etc/X11/Xsession.d$ cat 40x11-common_xsessionrc
# This file is sourced by Xsession(5), not executed.

#Source user defined xsessionrc (locales and other environment variables)
if [ -r "$USERXSESSIONRC" ]; then
  . "$USERXSESSIONRC"
fi

qxu@debian:/etc/X11$ grep USERXSESSIONRC Xsession
USERXSESSIONRC=$HOME/.xsessionrc
Qiang Xu
  • 143
2

If bash is your login shell, then it will try ~/.bash_profile, ~/.bash_login and ~/.profile in this order. It will however stop at the first one it finds.

If your ~/.profile is not sourced, then it means you have either one of the other two (possibly both) in your HOME directory. You should check which one, then place the new PATH statement in the first one.

MariusMatutiae
  • 4,372
  • 1
  • 25
  • 36
  • 3
    While that's a possible reason, those files did not exist in my system (I had checked even before asking). – sashoalm May 21 '14 at 13:25
1

When Bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.

So, when ~/.bash_profile exists, ~/.profile will never be read.

chaos
  • 48,171