startx
runs xinit
which starts an X server and a client session. The client session is ~/.xinitrc
if present, and otherwise /etc/X11/xinit/xinitrc
(the location may vary between distributions). What this script does varies between distributions. On Debian (including derivatives such as Raspbian), /etc/X11/xinit/xinitrc
runs /etc/X11/Xsession
which in turn runs scripts in /etc/X11/Xsession.d
. The Debian scripts look for a user session in other files (~/.xsession
, ~/.xsessionrc
, ~/.Xsession
) and, if no user setting is applicable, runs x-session-manager
(falling back to x-window-manager
if no [session manager] is installed, falling back to x-terminal-emulator
in the unlikely case that no window manager is installed).
If you want control over what gets executed, you can create one of the user files, either ~/.xsession
or ~/.xinitrc
. The file ~/.xsession
is also used if you log in on a display manager (i.e. if you type your password in a GUI window). The file ~/.xinitrc
is specific to xinit
and startx
. Using ~/.xsession
goes through /etc/X11/Xsession
so it sets up things like input methods, resources, password agents, etc. If you use .xinitrc
, you'll have to do all of these manually. Once again, I'm describing Debian here, other Unix variants might set things up differently. The use of ~/.xinitrc
to specify what gets executed when you run startx
or xinit
is universal.
Whether you use ~/.xinitrc
or ~/.xsession
, this file (usually a shell script, but it doesn't have to be if you really want to use something else) must prepare whatever needs to be prepared (e.g. keyboard settings, resources, applets that aren't started by the window manager, etc.), and then at the end run the program that manages the session. When the script ends, the session terminates. Typically, you would use exec
at the end of the script, to replace the script by the session manager or window manager.
Your system presumably has /usr/bin/startlxde
as the system-wide default session manager. On Debian and derivatives, you can check the available session managers with
update-alternatives --list x-session-manager
or get a more verbose description indicating which one is current with
update-alternatives --display x-session-manager
If LXDE wasn't the system-wide default and you wanted to make it the default for your account, you could use the following ~/.xsession
file:
#!/bin/sh
exec startlxde
On some Unix variants, that would only run for graphical logins, not for startx
, so you'd also need to create an identical ~/.xinitrc
. (Or not identical: in ~/.xsession
, you might want to do other things, because that's the first file that's executed in a graphical session; for example you might put . ~/.profile
near the top, to set some environment variables.)
If you want to try out other environments as a one-off, you can specify a different program to run on the command line of startx
itself. The startx
program has a quirk: you need to use the full path to the program.
startx /usr/bin/startkde
The startx
command also lets you specify arguments to pass to the server. For example, if you want to run multiple GUI sessions at the same time, you can pass a different display number each time. Pass server arguments after --
on the command line of startx
.
startx /usr/bin/startkde -- :1
The graphical user interface on traditional Unix systems, as well as most modern Unix systems other than Mac OS X, is built on the X Window System. One component, the X server, communicates with the hardware (display and input peripherals) and offers basic primitives to display windows and route user input. Other programs, said to be X clients, display windows and listen to user input by communicating with the X server.
In order to talk with the hardware, an X server may require special privileges; for example, on some systems, the X server is setuid root. Recent systems try to avoid having the X server run as root in order to improve security. Depending on the system, running an X server on the system console may be restricted to certain users, or to the user with physical access to the console.
The X server alone does nothing but display a hard-coded background pattern and a mouse cursor. In order to do anything useful, some clients need to be started, typically including a window manager.
The normal way to run a GUI session is to run a session manager program, which takes care of launching all desired clients (window manager, desktop widgets, clipboard manager, restored programs from the user's previous session, etc.). The session manager needs to be started after the X server since it will interact with it. Each desktop environment comes with its own session manager; just about any window manager can also be used as a session manager, and in a pinch a terminal running a shell can be seen as a minimalistic session manager — what matters is that the user has some way to launch the programs they want to run.
There are two traditional ways to launch a GUI session:
- If a user is already logged in, but they don't have a GUI yet, they can run the
xinit
command. This command starts an X server, then starts a session manager, and waits for the session manager to exit; then it kills the X server. This way, the client side of the session and the X server have the same lifetime. The startx
program is a small wrapper around xinit
.
- It's also possible to start a GUI before any user is logged in. In that case, the only client is a display manager, which provides a login prompt. Once a user has logged in, the display manager invokes their session manager. When the session manager exits, the display manager ensures that no more programs are running in that session, and shows a new login prompt.
Another way to see this is that in order to have a graphical login session, there needs to be a graphical interface and the user needs to log in. These two steps can be performed in either order: login then start the GUI (startx
method), or start the GUI then login (display manager method).
Other setups are uncommon but possible. For example, in a kiosk setup, the system startup scripts start an X server and a single full-screen client. In an autologin setup, the display manager runs a session manager for the default user at boot time.
Best Answer
i3
seems to be a X Window Manager. If it's your system's default window manager, it's registered with the 'alternatives' system - which you can check withupdate-alternatives --display x-window-manager
. This means that/usr/bin/x-window-manager
is a symlink to/etc/alternatives/x-window-manager
; this in turn is set by the 'alternatives' system to point toi3
.If you want to change the system default window manager, root can
update-alternatives --config x-window-manager
.If Xsession finds a window manager, it will make this the default program to start in the session. In Debian, this is done in
/etc/X11/Xsession.d/50x11-common_determine-startup
.If a users want to run a different program in their X session, then they can write a
~/.xsession
that starts (or execs) the desired program.