I found three configuration files.

  1. .xinitrc
  2. .xsession
  3. .xsessionrc

I know that the first one is for using startx and the second and third are used when using a display manager. But what is the difference between the last two?

2 Answers 2


~/.xinitrc is executed by xinit, which is usually invoked via startx. This program is executed after logging in: first you log in on a text console, then you start the GUI with startx. The role of .xinitrc is to start the GUI part of the session, typically by setting some GUI-related settings such as key bindings (with xmodmap or xkbcomp), X resources (with xrdb), etc., and to launch a session manager or a window manager (possibly as part of a desktop environment).

~/.xsession is executed when you log in in graphical mode (on a display manager) and the display manager invokes the “custom” session type. (With the historical display manager xdm, .xsession is always executed, but with modern display managers that give the user a choice of session type, you usually need to pick “custom” for .xsession to run.) Its role is both to set login-time parameters (such as environment variables) and to start the GUI session. A typical .xsession is

. ~/.profile
. ~/.xinitrc

~/.xsessionrc is executed on Debian (and derivatives such as Ubuntu, Linux Mint, etc.) by the X startup scripts on a GUI login, for all session types and (I think) from all display managers. It's also executed from startx if the user doesn't have a .xinitrc, because in that case startx falls back on the same session startup scripts that are used for GUI login. It's executed relatively early, after loading resources but before starting any program such as a key agent, a D-Bus daemon, etc. It typically sets variables that can be used by later startup scripts. It doesn't have any official documentation that I know of, you have to dig into the source to see what works.

.xinitrc and .xsession are historical features of the X11 Window system so they should be available and have a similar behavior on all Unix systems. On the other hand, .xsessionrc is a Debian feature and distributions that are not based on Debian don't have it unless they've implemented something similar.

.xprofile is very similar to .xsessionrc, but it's part of the session startup script some display managers including GDM (the GNOME display manager) and lightdm, but not others such as xdm and kdm.

  • 4
    Thank you! I wasn’t aware that ~/.xsessionrc is Debian-specific. It seems to be only briefly mentioned in Debian manual. Commented Jul 27, 2020 at 16:56
  • According to this link from arch wiki, .xprofile is not only sourced by GDM
    – smac89
    Commented Oct 1, 2020 at 2:59
  • NB (copied from man startx): "Note that in the Debian system, what many people traditionally put in the .xinitrc file should go in .xsession instead; this permits the same X environment to be presented whether startx, xdm, or xinit is used to start the X session. All discussion of the .xinitrc file in the xinit(1) manual page applies equally well to .xsession." I say this because the very existance of ~/.xinitrc "breaks" the Debian Alternatives System's x-session-manager link. HTH.
    – jaimet
    Commented Oct 26, 2023 at 12:44
  • @jaimet I have a .xinitrc and I've never had a problem on Debian. But of course that could be because I specifically wrote my configuration to be portable. What goes wrong when .xinitrc exists? Commented Oct 26, 2023 at 17:18
  • @Gilles'SO-stopbeingevil' From my testing today, I find that as soon as ~/.xinitrc exists, debian stops using x-session-manager/x-window-manager from the alternatives system. A few moments ago, I also found head_on_a_stick's post from Feb 2020: "If ~/.xinitrc is present then the alternatives system is not consulted. Whatever is listed in ~/.xinitrc will be run regardless of what is selected as the x-{session,window}-manager alternative.". HTH (et merci bcp pour tout ce que vous m'avez enseigné !)
    – jaimet
    Commented Oct 26, 2023 at 17:52

According to another discussion, startx + ~/.xsession and no ~/.xinitrc, results in reduced functionality (xfce4, sid)

Firstly: .xsessionrc is for holding global environment variables. The emphasis is mine.

Secondly: 40x11-common_xsessionrc in /etc/X11/Xsession.d is sourced before 50x11-common_determine-startup. So .xsessionrc is read before .xsession and any environment variables set will become available to applications run by the commands in .xsession.

Further reading:

  • 3
    .xsessionrc can be used to startup apps too -which is kind of contrary to the "global var" line. God It's a complicated mess.
    – RichieHH
    Commented Dec 12, 2020 at 11:26
  • @RichieHH Seconded: the debian wiki explicitly adds .'ing (dot'ing) other posix shell config files and directly running X client programs. HTH.
    – jaimet
    Commented Oct 26, 2023 at 15:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .