Say you want to use a GUI on a Linux-based server, and most gurus will chuckle and pat you on the head. But there are some very good reasons to have a GUI available on a server. Here’s how to go about getting a GUI on a Ubuntu server.
Decide Why You Need Both
The first step is deciding why you’d need both. Servers are meant to operate in the background, answering requests and sending out data. The cost of adding the overhead of a GUI (either from the perspective of storage, which matters less and less these days, RAM consumption, which is very important on a server, and traffic/throughput, which may sneak up on you if your server is remote) to these lean mean computing machines generally outweighs the benefits. But there are a couple of instances where it makes sense:
- If you’re looking for a primarily desktop machine that will also perform some server functions, you’re in luck: your existing Ubuntu machine is perfectly capable of acting as a web server, database server, or other type of server with the quick installation of some software. Try using “tasksel” as we explain here for a one-click LAMP server set-up. Ubuntu also has a new tool called juju, which allows you to install and run Charms, not unlike the way one-click installers on web hosts work. There are still only a few available, but as more of these recipes are added, it’s looking to be a great way to easily add new applications to your server.
- If you’re looking for a primarily server machine that you can administer via a GUI, you’ll need to do a little more work, but it’s still totally possible. This is a good solution if you’re just starting with server administration, and want some GUI tools around in case you get in a jam.
The instructions below assume you’re looking for the second type of install.
Consider the Following
Before you go about installing and configuring, take a moment to think about the following:
- Are you comfortable with the command line? If it’s a remote machine, you’ll still need to log into the server via terminal to start the GUI, then switch to another program to access it.
- Do you want the GUI to be running all the time? Bear in mind that having a desktop running all the time consumes resources such as CPU and RAM, so you may run into performance issues unless you upgrade your server hardware.
- Is the server directly accessible (e.g. via keyboard/mouse/monitor)? Is it on the local network or remote? If you’ll need to access the GUI over the network you’ll need to use a technology like RDP, VNC, or NX, with the latter being a good choice for remote machines where you may not be able to count on Ethernet speeds.
Let’s take a look at adding a GUI on a Ubuntu server that will be runnable on demand rather than all the time.
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
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:
The following command will start up X and the desktop of your choice when you issue from the command line:
This will allow you to start up LXDE when you need it, and when you exit, you’ll be back to command-line heaven.
Do you use GUI on a Ubuntu server? Do you have any thoughts or comments not covered in this article? Let us know in the comments below.
Our latest tutorials delivered straight to your inbox