GNOME Wayland – How to Set Environment Variables for GNOME on Wayland and Bash on Virtual Terminals

environment-variablesgnomeprofilewayland

Gnome 3.22 uses wayland by default. Gnome on wayland does not read ~/.profile (or ~/.bash_profile or /etc/profile). See https://bugzilla.gnome.org/show_bug.cgi?id=736660.

I have my initialization files set up as following:

  • .bash_profile does nothing but source .profile and .bashrc
  • .profile only sets environment variables like PATH and LC_MESSAGES
  • .bashrc sets some bash specific settings and aliases and environment variables for applications like less and grep.

The effect (before wayland) was following:

  • when I login graphically .profile was read and environment variables like PATH and LC_MESSAGES were set. when I open bash inside a terminal emulator then .bashrc was read.
  • when I login under a virtual terminal then .bash_profile was read which in turn reads .profile and .bashrc.
  • when I login using ssh then behaviour is similar to virtual terminal.

In all cases .profile and .bashrc were read and my environment was set up.

So now gnome 3.22 uses wayland and wayland does not read .profile. How can I set up my initialization files so that I again have the effects as described above?

Note that I do not insist that certain files (like .profile) are read. What I want is to have my environment set up in a sensible way. That means I want to keep bash specific settings to the bash initialization files and other settings to other initialization files. Also I would like to not copy the settings over different files.

I use arch linux. Answers for all distributions are welcome. When suggesting a workaround please also describe the side effects and the advantages and disadvantages.


update november 2017: as far as i understand the gnome developers have acknowledged that people expect their login shell config files (.profile and .bash_profile in case of bash) are sourced after login. regardless of text or graphical login. so my use case outlined above works again.

still the gnome developers want to move away from starting a login shell. it seems that the direction they are going is to use environmentd from systemd:

https://in.waw.pl/~zbyszek/blog/environmentd.html

it seems that it will take a while until all login methods are adapted to environmentd.

Best Answer

Systemd version 233 (March 2017) added support for setting environment variables in ~/.config/environment.d/*.conf. See the environment.d man page and the discussion that led to the feature on this preliminary PR and this final one.

Related Question