Ubuntu – what does startx command do

xorg

While reading about Ubuntu I found the following statement…..

If the display manager is not started by default in the default runlevel, you can start X a different way, after logging on to a text-mode console, by running startx from the command line.

What does it mean to be a default runlevel?
And when I tried this on my terminal I got this:

anupam@JAZZ:~$ startx

X: user not authorized to run the X server, aborting.
xinit: giving up
xinit: unable to connect to X server: Connection refused
xinit: server error

Best Answer

Once upon a time(1), when the memory of the computers was measured in kilobytes and the disks in megabytes, running the graphic interface all the time was considered harmful.

Most Unix computers were used for scientific computations and simulation in multi-user environments, and the graphic interface running on them would reduce the memory and CPU power available to them.

So when you needed a graphical interface you just started it with startx (2).

startx basically runs an Xserver (the graphical "driver") and a command which run on it, which is typically a window manager. By default the commands that are run are in ~/.xinitrc file in your home directory, or some generic system file otherwise.

Modern systems are thought from the bottom up to have a graphical system running all the time, so no one has probably checked the working of startx for ages -- that explains a lot of strange behavior you can have.

If you want to experiment and the feel the good old times, the best thing is doing the following:

A) install Xnest and fvwm. Xnest is a graphic server-within-a-server, a kind of server that will open as a window in your normal system. Fvwm is a very simple window manager which was very popular back then. You will need old pixmap fonts, too.

sudo apt-get install xnest fvwm 
sudo apt-get install xfonts-100dpi xfonts-100dpi-transcoded xfonts-75dpi-transcoded xfonts-75dpi 

B) write this file somewhere, for example in you home dir, and call it ~/test:

#!/bin/bash 
#
xterm & 
exec fvwm2

C) Run (notice: startx is normally run with first the client command, then a double dash, and then a server command. As I said, most new systems do not have sensible defaults for startx alone.).

cd ~
startx ~/test -- /usr/bin/Xnest -ac :1 -geometry 800x600

...and you have a 80ies workstation screen:

enter image description here

(You can have the menu by clicking on the "Xnest" desktop).

...and if you feel really adventurous, you can start a native session on another virtual console (read the other answers) by going to one of them with Ctrl-Alt-F1, loggin in, and

startx ~/test 

which will normally open on Ctrl-Alt-F8.

Notice: modern desktop environments are not designed to run simultaneously, for the same user, in two different consoles. So do not use gnome-shell or unity or modern things when doing this experiments, or you could mess up your configuration.


Footnotes:

(1) Speaking about around 1980-90 here.

(2) For example, I had a laptop with 256k of RAM. It was painfully slow in the (B&W!) graphic interface, but snappy in the console. So I did most of my work (editing C, LaTeX and similar files) in console mode, and switched to the graphic environment only when really needed.

Related Question