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?
<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3d4e5c4e55525c51507d5c4e4d544f58">[email protected]</a>:~$ echo $PATH /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="99eaf8eaf1f6f8f5f4d9f8eae9f0ebfc">[email protected]</a>:~$ source ~/.profile <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="245745574c4b454849644557544d5641">[email protected]</a>:~$ echo $PATH /home/sashoalm/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f78496849f98969b9ab79684879e8592">[email protected]</a>:~$
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
Method 2
Agree with @goldilocks mostely. Just want to add that the script to source ~/.profile is ~/.xsessionrc, instead of ~/.xsession.
Here is the rationale:
<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b3c2cbc6f3d7d6d1dad2dd">[email protected]</a>:/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 <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e3929b96a38786818a828d">[email protected]</a>:/etc/X11$ grep USERXSESSIONRC Xsession USERXSESSIONRC=$HOME/.xsessionrc
Method 3
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.
Method 4
When Bash is invoked as an interactive login shell, or as a
non-interactive shell with the--loginoption, 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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0