CentOS 7 is a very powerful, open source server platform. With this particular operating system, you can deploy very powerful web sites, containers, and so much more. But for some, the installation could “accidentally” wind up with a GUI-less platform (you must remember to select the GUI during installation). If you’re well versed in the Linux command line, that’s not a problem. But for those new or newish to Linux, a good GUI would go a very long way to assist the administration process.

Fortunately, for those that wound up with a GUI-less CentOS server, adding a graphical desktop environment into the mix is actually not that hard. I’m going to show you how to install the GNOME, KDE, XFCE, and Mate desktop environments and enable the graphical login. It’s actually much easier than you might expect.

Assumptions

For this to work, I will assume you already have CentOS 7 installed (without a desktop environment), you have access to either the root account or a user with sudo rights, and that your machine has an internet connection. Do note, although the installation of the GNOME environment will not require a reboot, to gain access to the graphical login will. Don’t worry, however, you can still get to your GNOME desktop without having to reboot.

SEE: Securing Linux policy (Tech Pro Research)

Installation

The installation of the GNOME desktop on CentOS 7 is handled via the groups option for the yum command. Before we actually run the installation, let’s update first. Issue the command sudo yum update to upgrade everything that can be upgraded. If the update process happens to upgrade the kernel, you will have to reboot to make those changes take effect.

Once the update finishes, issue the command:

sudo yum -y groups install "GNOME Desktop"

This installation may take a bit of time (depending upon the speed of your hardware and internet connection). Allow it to complete and you will be subsequently deposited back at your terminal window. To finish up the installation, issue the command:

echo "exec gnome-session" >> ~/.xinitrc

The above command will inform the startx command which desktop environment to run. This is important if you have more than one environment installed.

Starting GNOME

Before we make this process automatic, let’s test to make sure GNOME works. From the terminal window, issue the command startx. The GNOME desktop should start up and work exactly as expected (Figure A).

Figure A

SEE: Server deployment/migration checklist (TechRepublic)

GUI login

You may not want to have to issue startx every time you need to log into your server. If that’s the case, there’s a command for that. Open up a terminal window and issue the command:

systemctl set-default graphical.target

The next time you reboot, you’ll be greeted with the GUI login screen (Figure B).

Figure B

What about KDE, XFCE, or Mate?

Should GNOME not be your cuppa tea, you might prefer the KDE desktop environment. To install that particular desktop, the installation command would be:

sudo yum -y groups install "KDE Plasma Workspaces"

Once that command completes, inform startx with the command:

echo "exec startkde" >> ~/.xinitrc

The XFCE desktop can be installed/enabled with the following commands:

sudo yum -y groupinstall X11
​sudo yum --enablerepo=epel -y groups install "Xfce"
​echo "exec /usr/bin/xfce4-session" >> ~/.xinitrc

Fan of the Mate desktop? Install/enable that with the following:

sudo yum --enablerepo=epel -y groups install "MATE Desktop"
​echo "exec /usr/bin/mate-session" >> ~/.xinitrc

If you enable the GUI login (with the command systemctl set-default graphical.target), you should then be able to select the GUI you want at the login screen.

Your server, your way

As I say almost daily, one of the great things about Linux is that you can make it do what you want to do, exactly how you want it done. Adding a GUI to the platform is no exception (and perfectly illustrates that point).

If you’re newish to Linux administration, you probably want to start off your journey with a GUI. Install one of these and enjoy a more user-friendly server environment.

Subscribe to the Data Insider Newsletter

Learn the latest news and best practices about data science, big data analytics, artificial intelligence, data security, and more. Delivered Mondays and Thursdays

Subscribe to the Data Insider Newsletter

Learn the latest news and best practices about data science, big data analytics, artificial intelligence, data security, and more. Delivered Mondays and Thursdays