首页 > Sysadmin > 正文

How to Install and Configure a GUI on Linux

2026-10-31 Sysadmin

Linux systems boot to a text console by default. You can install and enable a graphical user interface (GUI) when needed. The steps below cover Debian/Ubuntu and RPM-based distros.

TL;DR: Check the Current Default Target First

systemctl get-default

graphical.target means the system boots into a graphical desktop; multi-user.target stops at a text login [2].

2. Confirm Whether a GUI Is Already Installed

systemctl is-active gdm

WSL2 verified: if no display manager is installed, the command returns inactive. If it returns active, gdm is already running.

3. Install a Desktop Environment

Debian/Ubuntu:

sudo apt update
sudo apt install ubuntu-desktop

RPM-based (Fedora/RHEL):

sudo dnf groupinstall "GNOME Desktop Environment"

The exact desktop package name varies by distro. On Debian-based systems you can also use tasksel to select the “Gnome Desktop” task [1].

4. Enable the Display Manager and Set the Default Target

sudo systemctl enable gdm
sudo systemctl set-default graphical.target

set-default works by changing the default.target symlink. The graphical.target unit also pulls in display-manager.service [2]. Running enable gdm only creates a wants symlink; it does not start the service immediately.

5. WSL and Graphical Environments

WSL verified (Ubuntu 24.04.4 LTS): the default target is already graphical.target, but there are no gdm/sddm service files. WSLg lets individual GUI apps run directly on the Windows desktop without a traditional display manager [3].

6. Troubleshooting Cheat Sheet and Limitations

Symptom Cause Fix
systemctl set-default errors Needs root Run with sudo
gdm enable fails gdm package not installed Install a display manager first
No desktop after WSL install WSL has no traditional display manager Use WSLg or RDP/VcXsrv
set-default takes no effect Current session not rebooted Reboot WSL or the physical machine

Limitations: the actual effect of sudo set-default on WSL2 is not fully verified; switching the default target after a reboot on physical hardware is untested; RPM desktop package names may differ from actual releases.

Not fully verified: full behavior of sudo systemctl set-default after password prompt on WSL2; gdm/sddm enablement and post-reboot startup; RPM desktop package names are based on documentation only.

Verified

  • Test machine: WSL2 Ubuntu 24.04.4 LTS, kernel 6.6.114.1-microsoft-standard-WSL2; 2026-10-30.
  • systemctl get-default: graphical.target.
  • apt-cache show ubuntu-desktop / kde-standard / xfce4: packages exist.
  • apt-get install --dry-run ubuntu-desktop: dependencies resolved.
  • systemctl is-enabled gdm: not-found; is-active gdm: inactive.
  • systemctl set-default: requires sudo, execution result not verified.
  • Not verified: physical machine reboot, full WSLg desktop experience, RPM-based actual installation.

References

Main commands tested on WSL Ubuntu (24.04); Debian-family and general distro behavior cross-checked against documentation.