What desktop environment does startx run, and how can I change it

profilestartxx11xinit

From many docs, I read that startx is starting LXDE in Raspbian OS. I am a little bit confused.

Will always startx run LXDE GUI?

Also I have seen example with using startlxde command. How is that command different and why startx and startlxde are running the same GUI(LXDE)? Or maybe it runs it because it is the default GUI?

How can I choose default GUI if I have multiple ones?

Could you please explain more details around the GUI in Linux systems?

Best Answer

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
Related Question