可以通过以下几种方法判断Ubuntu 22.04是否安装了图形界面(GUI):
1. 检查当前运行级别/目标
systemctl get-default
- 返回
graphical.target→ 已安装GUI并默认启动 - 返回
multi-user.target→ 无GUI(服务器版)
2. 检查显示管理器服务
systemctl status display-manager
- 显示
gdm3(GNOME)、lightdm或sddm等 → 已安装GUI - 显示 "Unit display-manager.service could not be found" → 可能无GUI
3. 检查已安装的桌面环境包
# 检查GNOME(Ubuntu默认)
dpkg -l | grep -E "ubuntu-desktop|gnome-desktop"
# 检查其他桌面环境
dpkg -l | grep -E "kde-desktop|xfce4|mate-desktop|lxde"
有 ubuntu-desktop 或 gnome-shell 等包 → 已安装GUI
4. 检查X11/Wayland会话
# 检查Xorg
ps aux | grep -E "Xorg|Xwayland"
# 检查当前显示协议
echo $XDG_SESSION_TYPE
# 返回 "x11" 或 "wayland" → 正在运行GUI
5. 快速可视化检查
# 如果有GUI,这些命令会打开窗口
which nautilus # 文件管理器
which gnome-terminal # 终端
6. 检查登录界面
重启后观察:
- 出现图形登录界面 → 有GUI
- 只有命令行登录提示 → 无GUI
7. 查看安装类型记录
# 查看安装日志
cat /var/log/installer/media-info
最直接的判断方法:
同时运行以下命令:
systemctl get-default && echo "---" && systemctl status display-manager --no-pager -l | head -10
结果解读:
- 两个检查都确认GUI → 确定安装
- 只有
graphical.target但无显示管理器 → 可能GUI损坏 - 两者都没有 → 无GUI(服务器版)
如果确定需要GUI但未安装,可以安装:
sudo apt update
sudo apt install ubuntu-desktop
CLOUD技术笔记