How to Use a GUI on a Ubuntu Server

Install and Configure

The first step is to determine what GUI you want. LXDE is a good choice because it runs very light, but it doesn’t include all the tools of a regular Ubuntu desktop. The next step then is to install the standard Lubuntu desktop on your server, with one of the following commands:
sudo tasksel install lubuntu-desktop
server-tasksel-lubuntu
Once the installation is done, the Light Display Manager (LightDM) may start up for you right away — it will on your next boot, in any case.
By default, GUIs are set to run on start-up. We’ll want to turn this off, since a “regular” boot for our machine should just be in “server mode.” This involves removing three scripts that start up LightDM:
  • one in “/etc/init.d” (where the base script to start the service lives)
  • one in “/etc/init”

  • one in “/etc/rcX.d” (directories containing links to the scripts depending on runlevel)
While explaining the “init” process and its runlevels is beyond the scope of this article, what you need to know is how to do the following:
  • Back-up (don’t just delete) the “/etc/init.d/lightdm” file. You’ll need to be root to do so, which makes the “/root/” directory a nice place to keep it out of the way.
  • Likewise, remove “/etc/init/lightdm.conf” and keep it somewhere safe.
  • Next, you’ll need to remove all links in “/etc/rc.d/*” that pointed to that. Fortunately, there’s a nice tool that will do so for you:
sudo update-rc.d lightdm remove
So now, how do you get to the GUI? You’ll use the startx command, but first you need to create a config file. Create a new text file in your home directory called “.xinitrc”, and for LXDE, add the following line followed by a return:
exec startlubuntu
The following command will start up X and the desktop of your choice when you issue from the command line:
startx
server-gui-lubuntu
This will allow you to start up LXDE when you need it, and when you exit, you’ll be back to command-line heaven.

Comments