3

I'm currently running Debian 10 Xfce and I would like to update my PATH variable to include /opt/bin and ~/.local/bin. As per these - 1 2 answers, I put the following lines in my ~/.profile file:

if [ -d "$HOME/.local/bin" ] ; then
        PATH="$HOME/.local/bin:$PATH"
fi

if [ -d "/opt/bin" ] ; then PATH="/opt/bin:$PATH" fi

Now, when I source .profile from terminal, everything works well and the PATH is updated. As per this answer, .profile is source at login, even with a GUI login. So, I expect the PATH variable to contain my modified locations when I login. Unfortunately, it does not.
Why isn't profile sourced at login?
How do I properly update my PATH to include the locations I want, if putting them inside .profile is not gonna work?

RogUE
  • 197
  • Whether your .profile is source on graphical login depends on your login manager. If I remember correctly, GDM and LDM do this, which one are you using? How do you log into your system? – terdon Feb 21 '21 at 15:09
  • @terdon I use lightdm login manager. – RogUE Feb 21 '21 at 15:26

2 Answers2

5

Quoting from the debian official documentation :

Graphical logins do not read a shell's startup files (/etc/profile and ~/.profile and so on) by default, but you as a user may choose to create a ~/.xsessionrc file which does this.

https://wiki.debian.org/EnvironmentVariables

D'Arcy Nader
  • 1,868
  • So, can I create an~/.xsessionrc and source my ~/.profile within it? – RogUE Feb 21 '21 at 14:34
  • yes, take a look at the link i posted. – D'Arcy Nader Feb 21 '21 at 14:35
  • Here's another Debian Wiki which says If you choose to dot in one of your regular shell dot files, make sure it does not use bash specific features, zsh specific features, ksh specific features, etc. How do I know if the .profile file contains bash specific features? – RogUE Feb 21 '21 at 14:47
  • take a look at your ~/.profile and you'll see – D'Arcy Nader Feb 21 '21 at 14:56
  • @RogUE there's no easy answer, I'm afraid. You need to know what features are shell-specific. One thing you should do is make sure you never use [[ ]] and always use [ ] instead. – terdon Feb 21 '21 at 15:05
  • @terdon There's not a lot of commands in my ~/.profile, just some if conditions, one of them sources /etc/bash_completion, another one sources ~/.bashrc, others set the PATH variable. – RogUE Feb 21 '21 at 15:09
  • @RogUE as long as your default shell is bash, then it's fine. If you switch to another shell, you should remove the mention of /etc/bash_completion and ~/.bashrc. – terdon Feb 21 '21 at 15:11
  • @terdon i don't think so, ~/.profile sources the bash files only if you use bash as default shell. – D'Arcy Nader Feb 21 '21 at 15:13
  • @terdon So, is there a proper method to do it? – RogUE Feb 21 '21 at 15:13
  • @RogUE what's wrong with the method suggested by the official documentation ? – D'Arcy Nader Feb 21 '21 at 15:14
  • @D'ArcyNader no, there's no magic system. If you are sourcing .profile from szh for example, and have those lines, then zsh will attempt to read .bashrc. .profile is just a shell script, it will do whatever you tell it to do. – terdon Feb 21 '21 at 15:16
  • @D'ArcyNader It might be my OCD, but this line in the official documentation caught my eyes: This is a quicky and dirty approach! Not for the pedantic user. – RogUE Feb 21 '21 at 15:19
  • @terdon i'm using a debian 10 and my ~/.profile says # if running bash if [ -n "$BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fi fi so it is checking if the default shell is using bash if not it' doesn't source bash files – D'Arcy Nader Feb 21 '21 at 15:20
  • @D'ArcyNader exactly: your profile is explicitly checking. But this is a Debian thing not a general one. You can't assume all profiles will be checking and most do not include that atrocity (OK, in my opinion) which makes your login shells behave like non login shells. – terdon Feb 21 '21 at 16:29
  • @terdon the question is about Debian 10 as it clearly says. – D'Arcy Nader Feb 21 '21 at 16:39
  • @D'ArcyNader sure, but my point was there is no magic system: .profile will do whatever you tell it to do. So if you, or your system, tell it to source .bashrc only if running bash, then that's what it will do. But if you don't explicitly tell it to check if you're running bash, then it won't. .profile is a file that is very, very commonly modified by users so you cannot assume it is the same as yours just because you run the same OS. I've had the same .bashrc and .profile files with few modifications for almost 20 years and more than 5 distros. – terdon Feb 21 '21 at 17:06
1

GNOME Terminal has an option to run the command as a login shell.

Other graphical consoles will at least let you explicitly configure the command to execute -- this can be bash --login. I found this the least painful way to get the behavior I (perhaps naively?) expected.

BobHy
  • 129