centos7安装GUI

升级安装更新安装包 sudo yum update 安装图形界面的桌面环境。 在CentOS 7上,有几个常用的桌面环境可供选择,包括GNOME、KDE、Xfce等。这里以安装GNOME为例 sudo yum groupinstall "X Window System" sudo yum group

升级安装更新安装包

sudo yum update

安装图形界面的桌面环境。

  • 在CentOS 7上,有几个常用的桌面环境可供选择,包括GNOME、KDE、Xfce等。这里以安装GNOME为例

sudo yum groupinstall "X Window System"
sudo yum groupinstall "GNOME Desktop"
  • 如果你想安装其他桌面环境,将上述命令中的"GNOME Desktop"替换为你想要安装的桌面环境的名称。

查看系统运行级别(centos 7)

[root@localhost App]# runlevel
N 5
第一个数为之前运行级别,后一个数为当前运行级别5

[root@localhost App]# systemctl get-default
graphical.target

# 临时切换系统运行级别
init X	

  • 查看target运行说明

[root@localhost App]# cat /etc/inittab
# inittab is no longer used when using systemd.
#
# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target
#
# systemd uses 'targets' instead of runlevels. By default, there are two main targets:
#
# multi-user.target: analogous to runlevel 3
# graphical.target: analogous to runlevel 5
#
# To view current default target, run:
# systemctl get-default
#
# To set a default target, run:
# systemctl set-default TARGET.target
ll /usr/lib/systemd/system/runlevel*target	# 查看所有target信息

[root@localhost App]# ll /usr/lib/systemd/system/runlevel*target
lrwxrwxrwx. 1 root root 15 Jul  5 10:40 /usr/lib/systemd/system/runlevel0.target -> poweroff.target
lrwxrwxrwx. 1 root root 13 Jul  5 10:40 /usr/lib/systemd/system/runlevel1.target -> rescue.target
lrwxrwxrwx. 1 root root 17 Jul  5 10:40 /usr/lib/systemd/system/runlevel2.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Jul  5 10:40 /usr/lib/systemd/system/runlevel3.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Jul  5 10:40 /usr/lib/systemd/system/runlevel4.target -> multi-user.target
lrwxrwxrwx. 1 root root 16 Jul  5 10:40 /usr/lib/systemd/system/runlevel5.target -> graphical.target
lrwxrwxrwx. 1 root root 13 Jul  5 10:40 /usr/lib/systemd/system/runlevel6.target -> reboot.target

切换运行环境

  • 使用systemctl get-default可以获得当前的默认target;

  • 使用systemctl set-default可以设置默认target,target可以是graphical.target、multi-user.target

  • //graphical.target表示开机将默认进入图形界面

  • //multi-user.target表示开机将默认进入文本界面

[root@localhost App]# systemctl get-default #查看默认运行
graphical.target

systemctl set-default multi-user.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.

[root@localhost App]# systemctl get-default
multi-user.target

  • 移除配置文件方法

rm -f /etc/systemd/system/default.target

设置命令行级别方法:

ln -sf /lib/systemd/system/runlevel3.target /etc/systemd/system/default.target 
或 
ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target 
或 
systemctl set-default multi-user.target

改回窗口级别方法:

ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target 
或 
ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target 
或 
systemctl set-default graphical.target 

启动Desktop

startx

init 5

当安装过程完成后,运行以下命令以将图形界面设置为默认启动:

sudo systemctl set-default graphical.target

重启系统以应用更改:

sudo reboot
  • init 3 //切换到命令行控制界面

  • init 5 //切换到图形化界面

查看graphical.target服务状态

Jul 11 10:58:07 localhost.localdomain systemd[1]: Reached target Graphical Interface.
[root@localhost ~]# systemctl status graphical.target
● graphical.target - Graphical Interface
   Loaded: loaded (/usr/lib/systemd/system/graphical.target; enabled; vendor preset: disabled)
   Active: active since Tue 2023-07-11 10:58:07 CST; 2h 43min ago
     Docs: man:systemd.special(7)

Jul 11 10:58:07 localhost.localdomain systemd[1]: Reached target Graphical Interface.

卸载

yum groupremove "X Window System" 
yum groupremove "GNOME Desktop"
LICENSED UNDER CC BY-NC-SA 4.0
评论
访问统计
总访问量: 👀| 访客数: 🚶‍♂️