.profile functionality inside X sessions

The Problem

Most display managers, when you log in, don't start up X in a way that would set up environmental variables for all the processes that would be spawned in the same way that console logins used to. Namely, your .profile isn't necessarily run. (Add link to bug reports about this behaviour, complete with WONTFIX.)

Dumb Per-User Solution

If it exists, a user's .xsessionrc is sourced earlyish in /etc/X11session.d/ processing. Every user who wants this sane behaviour can therefore just add the following to ~/.xsessionrc:

. $HOME/.profile

Hat-tip to gnarface on #devuan for independently concluding this is a workable solution.

Smarter Global Solution

Create this file as either /etc/X11/Xsession.d/10x11-profile or /usr/local/etc/X11/Xsession.d/10x11-profile and symlink.

# This file is sourced by Xsession(5), not executed.

# FatPhil wrote this on the principle that everything launched from an
# X session should have the same environment set up as everything
# launched from a terminal. And that's true for all users.
# Without it, every user would need to add ``. $HOME/.profile'' to
# their .xsessionrc, which seems like a needless waste of effort
# Install at or link to from /etc/X11/Xsession.d/10x11-profile

# Source user defined .profile (locales and other environment variables)
if [ -r "$HOME/.profile" ]; then
  . "$HOME/.profile"

This will now be run very early on in Xsession.d/ processsing, and everything in everyone's X session will have the same environment set up as if they'd all done the dumb per-user solution above.

NB: I have only deduced this works, not tested it!

Another hastily constructed page by Phil Carmody
Home / linux / X11-profile.html