Why does gdm-x-session source my .profile twice?

I have a line in my .profile like this:

export PATH="$HOME/.local/bin:$PATH"

However I noticed that my PATH env variable has the local bin directory duplicated. It looks like


I believe this is happening because gdm-x-session is sourcing my .profile twice. I added a logging message to my .profile and saw it twice in the journalctl --user output by gdm-x-session. I also found a bug entry from 2002 for a different Linux distro which might be related.

This issue does not present itself when logging in through the Linux virtual console.

Of course a workaround would be to make my .profile idempotent but I’d like to solve the deeper issue.

The default script tests the current path before inserting user-specific ones:
It looks like your customization is missing the necessary check.

Yeah that’s one workaround but I don’t think it gives GUI applications access to my local bin. I could also rename .profile to .bash_profile and that works perfectly. However, I would like to figure out why my current setup doesn’t work as expected.

If you look at /etc/profile near the end it has this comment

# Source global bash config, when interactive but not posix or sh mode
if test "$BASH" &&\
   test -z "$POSIXLY_CORRECT" &&\
   test "${0#-}" != sh &&\
   test -r /etc/bashrc
   # Bash login shells run only /etc/profile
   # Bash non-login shells run only /etc/bashrc
   # Check for double sourcing is done in /etc/bashrc.
   . /etc/bashrc

This means that logging in from the virtual console is treated differently than when opening a terminal window.

In both cases the users ~/.bashrc is used and things may be duplicated.

Having an entry duplicated in $PATH is not a serious error but may cause a very minute delay in response to a command that is located after searching the same path twice.

On my $PATH I also see /home/USER/.local/bin:/home/USER/bin twice. Once when added at the beginning of $PATH and once at the very end of $PATH.

Using the gnome terminal I see this in ~/.bashrc

# User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
export PATH

which adds the users path portion to the very beginning of the $PATH variable. Note that most users prefer this location so that their own commands may be found first without searching the entire $PATH.

then looking at ~/.bash_profile we see

# User specific environment and startup programs


export PATH

which adds the same path to the end of $PATH.

This seems the source of the duplicate entries in ones $PATH variable.

The file .bashrc already sets the entry /home/anon/.local/bin so your .profile just duplicates that.

# User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
export PATH

Previous discussion from January 2022:

A bad decision was made in Fedora 30 to fix a cockpit bug (1615131 , #12803) by moving PATH customizations from .bash_profile to .bashrc (commit , PR).

.bashrc is supposed to be only for interactive shells. .bash_profile should source .bashrc only if interactive:

 # .bash_profile
 # Get the aliases and functions
-if [ -f ~/.bashrc ]; then
-	. ~/.bashrc
+case "$-" in *i*)
+  if [ -f ~/.bashrc ]; then
+    . ~/.bashrc
+  fi;;
 # User specific environment and startup programs

Actually, with fedora 38 it resides in both .bashrc and .bash_profile.
One puts it at the beginning of $PATH and the other puts it at the end.

That depends on where you look. New users get a copy from /etc/skel/ and then it is up to the user to modify or not modify these files.

The latest change are as seen in https://src.fedoraproject.org/rpms/bash.git

--- a/dot-bash_profile
+++ b/dot-bash_profile
@@ -6,7 +6,3 @@ if [ -f ~/.bashrc ]; then
 # User specific environment and startup programs
-export PATH
diff --git a/dot-bashrc b/dot-bashrc
index 1130779..68854a1 100644
--- a/dot-bashrc
+++ b/dot-bashrc
@@ -5,6 +5,10 @@ if [ -f /etc/bashrc ]; then
        . /etc/bashrc
+# User specific environment
+export PATH
 # Uncomment the following line if you don't like systemctl's auto-paging feature:
 # export SYSTEMD_PAGER=
1 Like

This is false. It’s only in /etc/skel/.bashrc

True, I looked at the .bash_profile on my user and then later realized that is there because of the fact I have upgraded several releases, probably from at least F30, while keeping the data in /home.
The /etc/skel/.bash_profile is different than /home/USER/.bash_profile.