如何在 Ubuntu 服务器上安装桌面环境（GUI）
服务器 GUI
![](/data/attachment/album/202105/20/110026zm3mmam0iztaaczz.jpg)


你想在你的 Ubuntu 服务器上安装 GUI 吗？大部分情况下你是可以安装的，在本教程中我会详细介绍安装的步骤。


在正式开始之前，我来告诉你为什么服务器版的 Ubuntu 不带 GUI，以及在什么情况下你可以在服务器上安装 GUI。


### 为什么 Ubuntu 服务器没有 GUI？


你对比过 Ubuntu 的桌面版和服务器版会发现，两者的主要区别是服务器版缺少 GUI（比如 [桌面环境](https://itsfoss.com/what-is-desktop-environment/)）。Ubuntu 服务器基本上就是桌面版去掉图形模块后的降级版本。


这是刻意为之的。Linux 服务器需要占用系统资源来运行服务。图形化桌面环境会消耗大量的系统资源，因此服务器操作系统默认不包含桌面环境。


你可以在只有 512 MB RAM 的机器上使用 Ubuntu 服务器，但是 Ubuntu 桌面需要至少 2 GB 的 RAM 才能提供正常的功能。在服务器运行桌面环境被认为是浪费资源。


作为一个服务器使用者（或系统管理员），你应该通过命令行来使用和管理你的系统。为了达到这个水平，你需要掌握丰富的 Linux 命令相关的知识。


![Typically, you have to manage a server from the command line](/data/attachment/album/202105/20/110033myd4jtxyu7oukx34.png)


### 你是否真正需要在你的服务器上安装 GUI？


有些用户可能不太习惯在终端下使用命令行来完成工作。毕竟大部分用户是有条件通过图形界面操作计算机的。


你可能会在你的服务器上安装桌面环境并使用图形界面。大部分人不会这么干，但这是可行的。


但是这只有在你可以直接操作服务器时才行得通。假设你是在物理机器上运行它，比如服务器、台式机或笔记本电脑，抑或类似树莓派的设备。如果你可以直接操作宿主机系统，那么你还可以在运行在虚拟机上的服务器上安装。


如果你是通过 [云服务器提供商如 Linode、DigitalOcean 或 AWS](https://linuxhandbook.com/free-linux-cloud-servers/) 部署的服务器，那么安装 GUI 就行不通了。如果你想通过图形界面来管理你的远程服务器，你可以使用 Webmin 或 [Cockpit](https://linuxhandbook.com/cockpit/) 等工具。你可以在 Web 浏览器中通过这些工具使用和管理你的服务器。相比于成熟的桌面环境，它能大大降低资源消耗。


![Tools like Cockpit allow managing Linux servers graphically](/data/attachment/album/202105/20/110033no8z3dyayakg7od7.png)


### 如何在 Ubuntu 服务器上安装 GUI？


当你了解了基础知识后，我们一起来看看在 Ubuntu 服务器上安装桌面环境的步骤。


你需要做以下准备：


* 已经配置好 Ubuntu 服务器，且 RAM 至少 2 GB
* 管理员权限（你需要用 `sudo` 执行命令）
* 网络连接正常（你需要下载和安装新包）


我是在虚拟机上安装的 Ubuntu 服务器，并且我可以直接操作宿主机器。我使用同样的方法[在树莓派上安装了 Ubuntu 服务器](https://itsfoss.com/install-ubuntu-server-raspberry-pi/)。



> 
> 注意！
> 
> 
> 如果你是出于学习和调研等实验性的目的，那么你可以进行这些操作。请不要在生产环境的服务器上添加 GUI。后续删除 GUI 时可能会导致依赖问题，有些情况会破坏系统。
> 
> 
> 


#### 准备系统


首先，因为你将要做一些系统级的修改，因此先进行更新和升级以确保我们系统的包是最新的：



```
sudo apt update && sudo apt upgrade

```

#### 安装桌面环境


更新结束后，你就可以安装桌面环境了。


有两种方法：


* 使用 [apt](https://itsfoss.com/apt-command-guide/) 来安装包
* 使用一个名为 [tasksel](https://manpages.ubuntu.com/manpages/bionic/man8/tasksel.8.html) 的 Debian 工具，这个工具可以通过一条龙处理（任务）方式来安装多个包


任何一种方法都可以用完整包的方式来安装完整的桌面环境，就跟你从头安装桌面版本一样。我的意思是你可以得到跟桌面版本一样的所有的默认应用程序和工具。


如果你想使用 `tasksel`，需要先用下面的命令安装它：



```
sudo apt install tasksel

```

执行结束后，你就可以用 `tasksel` 来安装桌面环境（也叫 DE）了。


你可能知道有 [很多可用的桌面环境](https://itsfoss.com/best-linux-desktop-environments/)。你可以选择自己喜欢的一个。有些桌面环境对系统资源占用得多（像 GNOME），有些占用得少（像 Xfce、MATE 等等）。


你可以自己决定使用哪个 DE。我会安装 [GNOME 桌面](https://www.gnome.org/)，因为它是 Ubuntu 默认的桌面。之后我也会介绍其他桌面的安装。


如果你使用的是 `tasksel`，执行下面这条命令：



```
sudo tasksel install ubuntu-desktop

```

如果你使用 `apt`，执行下面这条命令：



```
sudo apt install ubuntu-desktop

```

这个过程可能会持续几分钟到一个小时，执行速度取决于你的网速和硬件。


我想提醒下，上面两个命令执行后都会安装完整的 GNOME 桌面环境。在本文中我两个命令都会执行，两个命令的结果是一样的。


#### 安装和配置显示管理器


安装完成后，你需要一个名为 [显示管理器](https://itsfoss.com/display-manager/) 或“登录管理器”的组件。这个工具的功能是在管理用户对话和鉴权时启动 [显示服务器](https://itsfoss.com/display-server/) 并加载桌面。


GNOME 桌面默认使用 GDM3 作为显示管理器，但从资源角度考虑它有点重。你可以使用更轻量级和资源友好的管理器。这里我们使用一个平台无关的显示管理器 [lightdm](https://wiki.debian.org/LightDM)。使用 `apt` 安装它：



```
sudo apt install lightdm

```

安装 lightdm 时系统会让我们选择默认的显示管理器，因为即使你可以安装多个管理器，也只能运行一个。


![Use the arrow key to select an option and then use the tab key to select  and press enter](/data/attachment/album/202105/20/110034cboov3kmo5gd6dby.png)


选择列表中的 “lightdm” 并点击 “<Ok>”。这应该用不了几分钟。完成后你可以用下面的命令启动显示管理器并加载 GUI：



```
sudo service lightdm start

```

你可以使用下面的命令来检查当前的显示管理器：



```
cat /etc/X11/default-display-manager

```

运行后得到的结果类似这样：


![Checking the default Display Manager](/data/attachment/album/202105/20/110034wg8rrevvv8rzeew4.png)


如果一切顺利，你现在会来到欢迎界面。


![Greetings screen of GNOME Desktop with LightDM on an Ubuntu server](/data/attachment/album/202105/20/110035fmszs8z4rt2ebrke.png)


输入你的凭证，你的桌面就运行起来了。


![GNOME Desktop fully loaded on Ubutnu server](/data/attachment/album/202105/20/110036i1jjbdj4sn64zjj3.png)


如果你想关闭 GUI，那么打开一个终端并输入：



```
sudo service lightdm stop

```

#### 安装其他的桌面环境（可选）


前面我说过我们可以选择不同的桌面。我们一起来看看一些其他的选项：


##### MATE


[MATE](https://mate-desktop.org/) 是基于 GNOME2 源码的轻量级桌面，它完全开源，是一个不错的选项。


用下面的命令来安装 MATE：



```
sudo tasksel install ubuntu-mate-core

```

或



```
sudo apt install ubuntu-mate-core

```

##### Lubuntu / LXDE/LXQT


如果你的系统资源有限或者电脑很旧，那么我推荐另一个轻量级的 [Lubuntu](https://lubuntu.net/)。使用下面的命令安装它：



```
sudo tasksel install lubuntu-core

```

或



```
sudo apt install lubuntu-core

```

##### Xubuntu / Xfce


[Xubuntu](https://xubuntu.org/) 是基于 [Xfce](https://www.xfce.org/) 的 Ubuntu 衍生版，轻量、简单、稳定但可高度定制。如果你想使用它，执行下面的命令：



```
sudo tasksel install xubuntu-core

```

或



```
sudo apt install xubuntu-core

```

还有一些桌面没有列出来，像 [KDE](https://itsfoss.com/install-kde-on-ubuntu/)，[Cinnamon](https://itsfoss.com/install-cinnamon-on-ubuntu/) 和 [Budgie](https://itsfoss.com/install-budgie-ubuntu/)，不代表它们不好，它们也都是非常卓越的，你可以自己尝试安装它们。


### 如何从 Ubuntu 服务器上删除 GUI？


如果你觉得桌面环境占用了太多的计算资源，你可以把之前安装的包删除掉。


请注意在某些情况下删除 GUI 可能会带来依赖问题，因此请备份好重要数据或创建一个系统快照。


* [如何从 Ubuntu 上删除包](https://itsfoss.com/uninstall-programs-ubuntu/)



```
sudo apt remove ubuntu-desktop
sudo apt remove lightdm
sudo apt autoremove
sudo service lightdm stop

```

现在重启你的系统。你应该回到了正常的命令行登录。


### 结语


在大多数场景下是可以安装桌面 GUI 的。如果你不适应命令行，那么请使用类似 [YunoHost](https://yunohost.org/) 的发行版的服务器，YunoHost 基于 Debian 系统，你可以通过 GUI 来管理服务器。


上面说了，如果你是从头安装系统，那么我建议你使用桌面版本以避免后续的步骤。


如果你有任何问题，请在评论区留言。你会在服务器上使用 GUI 吗？参照本文后你遇到了什么问题吗？




---


via: <https://itsfoss.com/install-gui-ubuntu-server/>


作者：[Chris Patrick Carias Stas](https://itsfoss.com/author/chris/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[lxbwolf](https://github.com/lxbwolf) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

Do you want to install GUI on your Ubuntu server? You can totally do that in most scenarios and I am going to discuss the steps in details in this tutorial.

But before you see that, let me tell you why the server edition does not come with GUI and in which cases you could install the GUI on your server.

## Why does Ubuntu server not have a GUI?

If you [compare Ubuntu desktop with server](https://itsfoss.com/ubuntu-server-vs-desktop/), the main difference will be the absence of GUI, i.e. [the desktop environment](https://itsfoss.com/what-is-desktop-environment/) in the server edition. Ubuntu Server is basically a striped-down version of Ubuntu desktop without the graphical modules.

This is intentional. A Linux server intends to use the system resources on running services. The graphical desktop environment consumes a lot of system resources and for this reason, the server operating systems do not include a desktop environment by default.

You may use an Ubuntu server on 512 MB of RAM but an Ubuntu desktop will need at least 2 GB of RAM to function decently. That’s considered a waste of resources in the server world.

As a server user (or sysadmin), you are expected to use and manage your system through command line. You should have decent knowledge of the Linux commands for this purpose.

![system restart required](https://itsfoss.com/content/images/wordpress/2021/05/system-restart-required-800x469.png)

## Do you really need to install GUI on your server?

Some people do not feel comfortable with the idea of doing everything using commands in the terminal. Most people are conditioned to use a computer graphically after all.

You may choose to install a desktop environment on your server and use it graphically. That’s not how most people do it but it’s an option.

But this works only if you have direct access to the server. If you are running it on a physical machine like a server, a desktop/laptop or devices like Raspberry Pi. You may also install it on a server running in a virtual machine if you have direct access to the host system.

If you have a server deployed using a [cloud server provider like Linode, DigitalOcean or AWS](https://linuxhandbook.com/free-linux-cloud-servers/?ref=itsfoss.com), installing GUI won’t be a good idea. If you have a remote server that you want to manage graphically, you may use tools like [Webmin](https://linuxhandbook.com/use-webmin/?ref=itsfoss.com) or [Cockpit](https://linuxhandbook.com/cockpit/?ref=itsfoss.com). These tools allow you to use and manage your servers graphically in a web browser. It consumes a lot less system resources than a full-fledged desktop environment.

![Cockpit interface](https://itsfoss.com/content/images/wordpress/2021/05/cockpit-2-2-800x450.png)

## How to install GUI on Ubuntu server?

Once the basics are clear, let’s see the steps for installing a desktop environment on an Ubuntu server.

You’ll need the following things:

- Ubuntu Server configured and running with at least 2 GB of RAM
- Administrative privileges (you need to run sudo commands)
- Internet connection (you are going to download and install new packages)

In my case, the Ubuntu server is installed in a virtual machine and I have direct access to the host machine. I have used the same method on an [Ubuntu server installed on a Raspberry Pi](https://itsfoss.com/install-ubuntu-server-raspberry-pi/).

Attention!

These things are fine for experimental purpose when you are learning and exploring. Please do not add GUI on a production server. Removing GUI afterwards could cause dependency issues and leave a broken system in some cases.

### Preparing your system

First, since you are going to make some system-wide modifications, let’s update & upgrade everything to make sure that our system is running the latest packages:

`sudo apt update && sudo apt upgrade`


### Installing the desktop environment

With the updates out of the way, you can continue with the installation of a desktop environment.

There are two ways to do this:

- Using
[apt](https://itsfoss.com/apt-command-guide/)to install the packages - Using a Debian tool called
[tasksel](http://manpages.ubuntu.com/manpages/bionic/man8/tasksel.8.html?ref=itsfoss.com)which helps with the installation of multiple packages in one coordinated process (tasks)

Either one will let you install the full desktop environment you choose as a full package, just like if you were installing the desktop version from scratch. By this, I mean that you will get all the default applications and tools you get with the desktop version.

If you want to use `tasksel`

you must first install it using the following command:

`sudo apt install tasksel`


Once this task is finished, you can use `tasksel`

to install the desktop environment (also referred as DE).

Now, you probably know that there are [several desktop environments available](https://itsfoss.com/best-linux-desktop-environments/). You may choose the one you like. Some desktop environments need more system resources (like GNOME) while some use fewer system resources (like Xfce, MATE etc).

It is up to you to decide which DE you would like to use. I am going with the [GNOME Desktop](https://www.gnome.org/?ref=itsfoss.com) since it is the default desktop for Ubuntu. Later on, I’ll share some tips for installing different desktops too.

If you are using `tasksel`

run this command:

`sudo tasksel install ubuntu-desktop`


if you want to use only apt, then run this command:

`sudo apt install ubuntu-desktop`


Depending on your connection speed and hardware this process will take from a couple of minutes to an hour.

I want to point that both actions will result in the full installation of the GNOME Desktop Environment. I ran both commands for the sake of this tutorial and ended up having the exact same results.

### Installing and setting up the display manager

After this process is completed, you will need a component called a [Display Manager](https://itsfoss.com/display-manager/), also known as a “login manager”. This tool is going to be responsible for starting the [display server](https://itsfoss.com/display-server/) and loading the desktop while managing user sessions and authentication.

By default, GNOME Desktop uses GDM3 as its display manager, but it is a bit heavy on the resources side. You can use something lighter and more resource-friendly. In this case, let’s go with [lightdm](https://wiki.debian.org/LightDM?ref=itsfoss.com), a platform independent display manager. Install it with apt:

`sudo apt install lightdm`


When installing lightdm the system is going to ask for a default display manager because only one can run at a time, although you can have several installed.

![Installing display manager on Ubuntu server](https://itsfoss.com/content/images/wordpress/2021/05/installing-gui-ubuntu-server-select-dm.png)

Just choose **lightdm** from the list and hit **<Ok>**. This shouldn’t take more than a couple of minutes. After this task is done, you can then start the display manager and load the GUI with the following command:

`sudo service lightdm start`


If you want to check what display manager is configured in your system you can run:

`cat /etc/X11/default-display-manager`


and you will get a prompt similar to this:

![installing gui ubuntu server default](https://itsfoss.com/content/images/wordpress/2021/05/installing-gui-ubuntu-server-default.png)

If everything went according to the plan, you will have a greeting screen loaded.

![installing gui ubuntu server gnome desktop greet](https://itsfoss.com/content/images/wordpress/2021/05/installing-gui-ubuntu-server-gnome-desktop-greet.png)

Enter your credentials and you will have your desktop running.

![installing gui ubuntu server gnome desktop](https://itsfoss.com/content/images/wordpress/2021/05/installing-gui-ubuntu-server-gnome-desktop.png)

If you want to shutdown the GUI open a terminal window and type:

`sudo service lightdm stop`


### Installing other desktop environments (optional)

Earlier on I said that we could choose different desktops, so let’s take a look at some alternatives.

#### MATE

[MATE](https://mate-desktop.org/?ref=itsfoss.com) is a lightweight desktop based on GNOME2 base code, it’s fully open source and a very nice option.

To install MATE, you would run:

`sudo tasksel install ubuntu-mate-core`


or

`sudo apt install ubuntu-mate-core`


#### Lubuntu / LXDE/LXQT

[Lubuntu](https://lubuntu.net/?ref=itsfoss.com) is another lightweight option which I recommend if your system is low on resources or if you are giving new life to an older computer. Install it using this command:

`sudo tasksel install lubuntu-core`


or

`sudo apt install lubuntu-core`


#### Xubuntu / Xfce

[Xubuntu](https://xubuntu.org/?ref=itsfoss.com) is an Ubuntu derivative based on the [Xfce](https://www.xfce.org/?ref=itsfoss.com) desktop environment that is light, simple, stable, but it’s also highly customizable. If you want to try it, use the following command:

`sudo tasksel install xubuntu-core`


or

`sudo apt install xubuntu-core`


I’m leaving some other desktops out, like [KDE](https://itsfoss.com/install-kde-on-ubuntu/), [Cinnamon](https://itsfoss.com/install-cinnamon-on-ubuntu/), and [Budgie](https://itsfoss.com/install-budgie-ubuntu/), not for anything wrong, they are all excellent desktops too and you are free to install them as you want.

## How to remove the GUI from Ubuntu server?

If you realize that the desktop environment is taking too much computing resources, you may remove the packages you installed previously.

Please keep in mind that it may cause dependency issues in some cases so please make a backup of your important data or create a system snapshot.

You know [how to remove packages from Ubuntu](https://itsfoss.com/uninstall-programs-ubuntu/):

```
sudo apt remove ubuntu-desktop
sudo apt remove lightdm
sudo apt autoremove
sudo service lightdm stop
```


Reboot your system now. You should be back to the normal command line login.

## Wrapping up

Installing a GUI for a desktop is possible but not needed in most scenarios. If you are not too comfortable with the command line, use a server distribution like [YunoHost](https://yunohost.org/?ref=itsfoss.com) that is built on top of Debian to give you a server that can be managed via GUI.

You may also use a tool like Webmin that allows you to manage the server via a web browser.

[How to Install Webmin on Ubuntu Linux [and Configure It]Learn to install and configure Webmin to manage Linux servers remotely and graphically.](https://linuxhandbook.com/use-webmin/)![](https://linuxhandbook.com/content/images/2020/06/install-webmin-1.png)


![](https://linuxhandbook.com/content/images/2020/06/install-webmin-1.png)

That said, if you are installing a system from scratch, then I’d recommend that you go with a desktop version and avoid the extra steps afterward.

With this information, I leave the comment section to you. Do you use GUI on a server? Did you face any issues in following this tutorial?