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?


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:

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
|improve this answer|||||
  • I am on Debian 9. My machine boots to tty1. From my login running startx starts the default Xfce4 session. From my wife's user login on tty1 or tty2. Her startx command is set to run Cinnamon (specified in ~/.xsession). For the second X server I do not have to specify the $DISPLAY as noted in the last part of your answer. Although that certainly does work. It automatically makes it the second $DISPLAY etc. The setup is great though. There is no logging in and out of a graphical session, just a keyboard shortcut to switch user profiles. Thanks for this helpful answer! – jbrock Oct 26 '17 at 16:28

No: startx is configurable. According to the manual page:

To determine the client to run, startx first looks for a file called .xinitrc in the user's home directory. If that is not found, it uses the file xinitrc in the xinit library directory.

startx is not the only way to start X (as you see from startlxde). The startx manual page helps again:

The startx script is a front end to xinit(1) that provides a somewhat nicer user interface for running a single session of the X Window System. It is often run with no arguments.

On the other hand, if you want to choose a GUI (LXDE, KDE, etc), then xdm and look-alikes such as kdm, gdm or LightDM are used for selecting different desktop types. On Debian I generally use kdm, because that allows different desktop types. The packagers for gdm disallow most of the desktop types, making it unsuitable for my needs.

xdm uses a different set of scripts to start, e.g., your ~/.xsession script along with system scripts. The look-alikes may ignore this, and use their own scripts. But it is a starting point.

|improve this answer|||||
  • So, somwhere in the conf files it is written to run LXDE for example? – CuriousGuy Nov 15 '15 at 21:05
  • .xinitrc is a script, which makes it configurable. It could run LXDE directly if coded to do this. – Thomas Dickey Nov 15 '15 at 21:07
  • 1
    startlxde isn't a frontend to xinit, it's a launcher for the LXDE session manager. It isn't a replacement for startx, it's something you can execute in ~/.xinitrc. – Gilles 'SO- stop being evil' Nov 15 '15 at 22:06
  • Then it needs some documentation. Seriously, a good answer points the OP in the direction of documentation rather than attempting to rephrase it (unless one has some commentary to make upon the documentation, to make better sense of it). – Thomas Dickey Nov 15 '15 at 22:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.