In Ubuntu 16.04 with LXDE or Gnome,

  • how can I find out the environment variables created when Ubuntu was started with graphical interface?

  • when Ubuntu was started with graphical interface, which startup files are read and executed, /etc/profile, /etc/profile.d/*, ~/.profile, ~/.bash_profile, /etc/environment, /etc/bash.bashrc, ~/.bashrc?


  • Assuming LightDM, the /usr/sbin/lightdm-session file is part of the answer. There you can see that for instance ~/.profile is sourced when LightDM starts a user session. Apr 18, 2018 at 11:03

1 Answer 1


This is quite complex.

Pam also can add environment variables, as well as other things (login program, getty, whatever...).

What I used to do is to add lines of the style (see this)

export CALLED_IN_ETC_PROFILE=$(date date +%s.%N) 

in all suspicious files, and then look at the result for example using https://askubuntu.com/a/356973/16395.

To find which program/file could be responsible of the setting of a variable, you can try to look at the process tree of a shell into a terminal emulator:

[romano:/etc/X11/Xsession.d] % pstree -a -s -l -p -u $$
systemd,1 splash
          └─gdm-x-session,3807,romano --run-script gnome-session --session=gnome
              └─upstart,3824 --user
                          └─pstree,11831 -a -s -l -p -u 11224

...I think that to start the graphic session, gdm-x-session is started from a user shell (note the UID change in the chain) in non-interactive mode, so that .profile is read (but not .bashrc, which is read by the shell in terminal emulator).

The tree is somewhat different if called from the gnome-shell:

bash-4.3$ pstree -a -s -l -p -u $$
systemd,1 splash
          └─gdm-x-session,3807,romano --run-script gnome-session --session=gnome
              └─upstart,3824 --user
                  └─gnome-session-b,4162 --session=gnome
                          └─xterm,11882 -e bash --noprofile --norc
                              └─bash,11884 --noprofile --norc
                                  └─pstree,11885 -a -s -l -p -u 11884

but this is expected.

BTW, a lot of environment variables could also be set before the UID change to the user; there are a lot of scripts in /etc/X11/Xsession.d and around that the X server, gdm (or whichever display manager you use), that can set environment variables.

  • Thanks. I found that in a shell started by Alt+F2 and lxterminal -e bash --noprofile --norc, PATH contains a path I set in ~/.profile. So does it mean Ubuntu reads and executes ~/.profile when it is started with graphical interface? What startup files does your Ubuntu read and execute when it is started with graphical interface?
    – Tim
    Apr 17, 2018 at 16:03

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.