Skip to main content

How to switch between the CLI and GUI on a Linux server

Learn how to change between the command-line interface and the graphical user interface by editing the boot target.
Command line output in the terminal

Image by joffi from Pixabay

What do you do if your server boots to a graphical user interface (GUI), but you need it to boot to the command-line interface (CLI) for security and performance reasons? In days past, you would have edited the /etc/fstab file so that, instead of booting to runlevel 5 (the GUI), it booted to runlevel 3 (the CLI). However, with the advent of the systemd system manager, you must do something a bit different.

First, you no longer use the runlevel term. Instead, you refer to boot choices as targets. The two primary targets for this scenario are (the CLI) and (the GUI). The may be loosely associated with the legacy runlevel 3 concept, while the is similar to runlevel 5.

It's possible to switch targets manually, and you can also configure automatic or default boot targets. This article aims to explain both options.

Identify the current target

It's probably clear when you boot the system which target is the default. However, to confirm the default, use the systemctl command along with the get-default subcommand:

$ sudo systemctl get-default

The result will likely display either the or

Change targets manually

You can switch between targets on the fly by using the isolate subcommand. Perhaps you have a long checklist of administrative tasks, and it would be simplest for you to accomplish these in a GUI, but your server boots to the CLI. You can switch to the GUI, perform your tasks, and then switch the system back to the more efficient CLI.

Here's the command to launch the GUI from the

$ sudo systemctl isolate

Switch back by specifying the with this command:

$ sudo systemctl isolate

Those commands are useful for the current runtime, but what about configuring a default for when the system boots?

[ Free online course: Red Hat Enterprise Linux technical overview. ]

Set a default target

The default target represents the interface presented when the system first boots. Booting a server to a CLI for efficiency and security is common. The CLI consumes far fewer resources and contains less software to patch and worry over. Newer administrators or those migrating from another server platform may not be comfortable enough with Bash to work effectively at the command line. End-user workstations rarely boot to the CLI because the user typically needs graphics-based software, such as productivity suites and web browsers. For these users, the performance hit is worth the convenience.

Use the following systemctl command to configure the default startup target as the CLI:

$ sudo systemctl set-default

Use the argument to set the GUI as the default.

Try it

Try the following exercise if you have a systemd-based distribution available, such as Red Hat Enterprise Linux (RHEL).

Check the current default target:

$ sudo systemctl get-default

Switch to the opposite target (for example, if your system boots to the GUI, switch to the CLI):

$ sudo systemctl set-default

Reboot and confirm the appropriate target launched:

$ sudo systemctl reboot

Manually switch targets:

$ sudo systemctl isolate

Configure the system back to the original target:

$ sudo systemctl set-default

Reboot and then confirm the default target:

$ sudo systemctl reboot

If you don't have access to a system to experiment with, I encourage you to create a simple lab environment for these types of learning opportunities.

Understand target files

Targets are managed by .target files that simply group units and dependencies into a convenient format. It's really the .unit files that define exactly what services and other features start when the target is initiated. Enabling and disabling services and daemons adds and removes these components from the startup options:

$ sudo systemctl enable sshd
$ sudo systemctl disable sshd

Wrap up

This article covers the mechanics of identifying, switching, and setting targets on the system. These targets are managed via .target files. You can configure automatic startup options by using the set-default subcommand or manually switch targets with the isolate subcommand. I encourage you to walk through the exercise above; hands-on experience is essential for day-to-day administration and certification exams such as the Red Hat Certified System Administrator (RHCSA).

Check out these related articles on Enable Sysadmin

Topics:   Certification   Linux   RHEL  
Author’s photo

Damon Garn

Damon Garn owns Cogspinner Coaction, LLC, a technical writing, editing, and IT project company based in Colorado Springs, CO. Damon authored many CompTIA Official Instructor and Student Guides (Linux+, Cloud+, Cloud Essentials+, Server+) and developed a broad library of interactive, scored labs. He regularly contributes to Enable Sysadmin, SearchNetworking, and CompTIA article repositories. Damon has 20 years of experience as a technical trainer covering Linux, Windows Server, and security content. He is a former sysadmin for US Figure Skating. He lives in Colorado Springs with his family and is a writer, musician, and amateur genealogist. More about me

Red Hat Summit 2022: On Demand

Get the latest on Ansible, Red Hat Enterprise Linux, OpenShift, and more from our virtual event on demand.

Related Content