24

We have installed Ubuntu desktop edition on our development server. Now that we have it in a data center we would like to strip it down to a server edition.

Is there an easy way of doing so rather than just going in and uninstalling packages by hand?

Bernmeister
  • 1,149

4 Answers4

15

It's possible to do it the other way around, but I've never seen anyone who was able to do this simply by installing a metapackage or something.

Your best bet is either:

  • a clean install
  • manually removing unneeded packages and installing the server components you need
Nathan Osman
  • 32,495
13

You can remove ubuntu-desktop and simultaneously auto-remove all its orphaned dependants:

sudo apt-get autoremove ubuntu-desktop

Add the --purge option if you also want to remove the configuration of the affected packages (and not keep it for possible later reinstallation).

If you have any other Desktop remove them as well. if you reboot after this you should have no GUI to log into. If you purge a program rather than just removing it you also remove any config files that may remain.

As Rinzwind suggests try sudo apt-get remove gnome-*.

Before Ubuntu 16.04 it also provides a special kernel package for server installations, linux-image-server:

  • sudo apt-get install linux-image-server and reboot.

Then I suggest you install the server applications you want, like ssh-server.


But as always it's better to make a clean install. It gives less risk of errors and broken packages.

David Foerster
  • 36,890
  • 56
  • 97
  • 151
Alvar
  • 17,038
12

Note: as stated in comments, tasksel should only be used to install tasks, not remove them. In this specific task (remove desktop -> install server) it seems to work fine. So use it with caution.


You can try tasksel. With it, you can do what you want by selecting Basic Ubuntu Server and unchecking Ubuntu desktop.

sudo apt-get install tasksel

tasksel screen

Salem
  • 19,864
  • 6
  • 65
  • 90
2

If you want to just not run the DM and WM on startup but keep the ability to run them at will you can run:

sudo systemctl set-default runlevel3.target

then reboot.

The system will boot to runlevel 3 (init 3) which does not start the DM and WM and all the other stuff related to the desktop environment, but starts everything else. When the system boots into the tty1 terminal at the console, you can log in then

sudo init 5

to get to the desktop environment login.

On the ubuntu and xfce4 desktops I was testing with the GUI logout button hung my system.
On the ubuntu desktop, the power down and restart buttons worked fine; the xfce4 desktop only has a logout button.

The safe way to exit back to tty only is to open a terminal and run:

sudo init 3