10

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:~$ 
  • Have you tried adding it to /etc/profile? – MariusMatutiae May 21 '14 at 13:10
  • 2
    I don't want it to be global for all users, just for a single user. – sashoalm May 21 '14 at 13:11
12

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.

  • 2
    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
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.

  • 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
2

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
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.

  • 4
    Yes, but it does not exist in my case. – sashoalm May 21 '14 at 13:24

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.