You are not logged in.

#1 2021-11-12 20:40:25

jc65536
Member
Registered: 2021-07-02
Posts: 10

Gnome not sourcing ~/.profile on login

I'm using the latest version of Gnome 41.

The contents of my .profile:

PATH="$PATH:$HOME/bin"

I've also tried the following variations of .profile:

PATH="$PATH:~/bin"
export PATH="$PATH:$HOME/bin"
export PATH="$PATH:~/bin"

When I restart, login, open a new terminal and type echo $PATH, the output is

/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/lib/jvm/default/bin

Am I going crazy? Why isn't my .profile being sourced?

Offline

#2 2021-11-12 20:45:09

ugjka
Member
From: Latvia
Registered: 2014-04-01
Posts: 1,813
Website

Re: Gnome not sourcing ~/.profile on login

[ugjka@ugjka ~]$ cat .bash_profile 
#
# ~/.bash_profile
#

[[ -f ~/.bashrc ]] && . ~/.bashrc
[[ -f ~/.profile ]] && . ~/.profile

https://ugjka.net
paru > yay | webcord > discord
pacman -S spotify-launcher
mount /dev/disk/by-...

Offline

#3 2021-11-13 00:02:22

jc65536
Member
Registered: 2021-07-02
Posts: 10

Re: Gnome not sourcing ~/.profile on login

My .bash_profile did not source .profile, but shouldn't gdm source .profile by itself?

Edit:

Even after editing my .bash_profile to source .profile, and after rebooting, my $PATH still doesn't get set.

Last edited by jc65536 (2021-11-13 00:04:34)

Offline

#4 2021-11-13 01:06:47

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,732
Website

Re: Gnome not sourcing ~/.profile on login

jc65536 wrote:

shouldn't gdm source .profile by itself?

No.

Offline

#5 2021-11-13 03:11:58

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,548
Website

Re: Gnome not sourcing ~/.profile on login

I think you're asking the wrong question: should a display manager source files used only by the command line shell?  Nope.

But the shell started by any gui terminal emulator should.  And if this isn't happening, the problem is not with GDM, but with the terminal emulator and / or it's configuration.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#6 2021-11-13 13:50:27

stanczew
Member
Registered: 2021-03-02
Posts: 63

Re: Gnome not sourcing ~/.profile on login

Trilby wrote:

I think you're asking the wrong question: should a display manager source files used only by the command line shell?  Nope.

Both SDDM and GDM do in fact source those files when launching a graphical session:
SDDM's Xsession
SDDM's wayland-session
GDM's Xsession

However in case of GDM the wrapper script is only for X session, not Wayland – I don't know how Wayland environment is set up in such case.

Trilby wrote:

But the shell started by any gui terminal emulator should.  And if this isn't happening, the problem is not with GDM, but with the terminal emulator and / or it's configuration.

But the shell started by a GUI terminal emulator will not be a login shell, so .profile will not be sourced: https://wiki.archlinux.org/title/Bash#C … tion_files
Proper configuration in this case means that the display manager will pick up the environment variables (from whatever source), so that any GUI terminal emulator inherits them.

Offline

#7 2021-11-13 15:09:31

ugjka
Member
From: Latvia
Registered: 2014-04-01
Posts: 1,813
Website

Re: Gnome not sourcing ~/.profile on login

I run Gnome on Wayland via GDM and .profile gets sourced

For example I can launch programs in my custom PATH with Alt+F2 not just via Bash

[ugjka@ugjka ~]$ cat .profile 
export PATH=${HOME}/perl5/bin:${PATH}
export PATH=${HOME}/.local/bin:${PATH}
export PATH=${HOME}/bin:${PATH}
export PATH=${HOME}/go/bin:${PATH}
export PATH=${HOME}/.npm-packages/bin:${PATH}
export PATH=${HOME}/.gem/ruby/2.7.0/bin/:${PATH}

Last edited by ugjka (2021-11-13 15:15:45)


https://ugjka.net
paru > yay | webcord > discord
pacman -S spotify-launcher
mount /dev/disk/by-...

Offline

#8 2022-03-10 13:53:51

BrianDMS
Member
From: Amsterdam, Netherlands
Registered: 2022-03-10
Posts: 14

Re: Gnome not sourcing ~/.profile on login

Gnome wiki states that the Wayland session does not run a login shell, therefore as much as I hate it, ~/.profile not being sourced is the expected behaviour.
On a fresh Arch install, this is indeed the case, however, according to my limited testing, /etc/profile does get sourced, so a possible solution could perhaps be to source ~/.profile in /etc/profile?

ugjka wrote:

I run Gnome on Wayland via GDM and .profile gets sourced

Could you please verify this? I've read countless bug reports and documentations on this topic and this should not work according to most sources as well as my own testing.
If you can figure out how it works on your system, please let us know, this issue has been bugging me for a year.
Maybe try to trace back how the files are sourced by your shell by setting some variables and seeing if they get exported or overwritten?

EDIT: i just noticed your previous response where you read .profile in .bash_profile, this works and made me realize what the issue is, thank you!
What I wrote used to be correct but isn't true anymore, I'll explain in the followup reply

Last edited by BrianDMS (2022-03-10 14:32:45)


alias ffs='sudo $(fc -ln -1)'

Offline

#9 2022-03-10 14:31:58

hoffer
Banned
From: Latvia
Registered: 2022-02-07
Posts: 13
Website

Re: Gnome not sourcing ~/.profile on login

BrianDMS wrote:

Gnome wiki states that the Wayland session does not run a login shell, therefore as much as I hate it, ~/.profile not being sourced is the expected behaviour.
On a fresh Arch install, this is indeed the case, however, according to my limited testing, /etc/profile does get sourced, so a possible solution could perhaps be to source ~/.profile in /etc/profile?

ugjka wrote:

I run Gnome on Wayland via GDM and .profile gets sourced

Could you please verify this? I've read countless bug reports and documentations on this topic and this should not work according to most sources as well as my own testing.
If you can figure out how it works on your system, please let us know, this issue has been bugging me for a year.
Maybe try to trace back how the files are sourced by your shell by setting some variables and seeing if they get exported or overwritten?

I suppose this part is relevant:

[ugjka@ugjka ~]$ cat .bash_profile
#
# ~/.bash_profile
#

[[ -f ~/.bashrc ]] && . ~/.bashrc
[[ -f ~/.profile ]] && . ~/.profile

Because:

https://www.linuxfordevices.com/tutoria … sh-profile

What is the .bash_profile file in Linux?

The .bash_profile file is another bash shell script file which we can see as a config file. It is stored at ~/.bash_profile.

However, unlike the .bashrc file, it gets executed every time a user logs into a system.

In simple words, it is invoked when you enter your username and password to log in on your Linux system. This login can be both local or remote. It is different from a regular bash shell invocation and is seen as a login shell mode session.

So, a user login sources .bash_profile and that sources .profile


https://ugjka.net

I'm ugjka, I lost my account

Offline

#10 2022-03-10 14:38:19

BrianDMS
Member
From: Amsterdam, Netherlands
Registered: 2022-03-10
Posts: 14

Re: Gnome not sourcing ~/.profile on login

hoffer wrote:

I suppose this part is relevant:

[ugjka@ugjka ~]$ cat .bash_profile
#
# ~/.bash_profile
#

[[ -f ~/.bashrc ]] && . ~/.bashrc
[[ -f ~/.profile ]] && . ~/.profile

You're absolutely correct, I totally missed that, just edited my reply and since there's a little bit more to it, i'll attempt to write an exhaustive explanation of how it works so that the thread could be marked as solved and help others with the same issue.


alias ffs='sudo $(fc -ln -1)'

Offline

#11 2022-03-10 15:27:21

BrianDMS
Member
From: Amsterdam, Netherlands
Registered: 2022-03-10
Posts: 14

Re: Gnome not sourcing ~/.profile on login

Quick followup and my final conclusions after some testing

Either the Gnome documentation and bug report threads are entirely incorrect, or this behaviour is somehow modified on Arch, regardless, here's how I believe it currently works:

In contrary to the Gnome documentation, during the log-in process before gnome session is started by gdm, the user shell (Bash by default) is called as a login shell.
When called as a login shell, Bash sources /etc/profile and then attempts to source its shell-specific profile from the user directory: ~/.bash_profile.
Now, only if ~/.bash_profile does not exist, Bash sources the shell-agnostic ~/.profile file, this is the reason why ~/.profile is ignored by default.
This is described very well on the wiki and makes perfect sense. The issue is - Gnome documentation states that a login shell is not called by GDM, whereas it clearly is.

If the shell-specific .bash_profile is used, .profile is not really necessary (it's not even created by default anymore)
Alternatively .bash_profile can simply be deleted and replaced by shell-agnostic .profile, I'm not sure if this has any negative consequences.

Gnome seems to be a child process of this instance of the user shell, as it inherits all environment variables set and exported in /etc/profile and ~/.profile or its shell-specific equivalent.
I couldn't find the bash configuration file that specifies it's behaviour when used as a login shell, perhaps it's hard-coded?
Lastly, this behaviour might differ between different shells, though i expect it would work in a similar way.

It would be great if the information about Gnome/GDM calling the user shell as a login shell was added to the GDM or Gnome wiki page, as there's a lot of conflicting information on this.
If you can OP, mark this as solved so that others can easily find this answer, myself I struggled for a long time to find out exactly how this works.


alias ffs='sudo $(fc -ln -1)'

Offline

Board footer

Powered by FluxBB