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,231
  • 2
    Re-installing is best: the server CD has kernel params set that the desktop is lacking (you can get them ofcourse with the desktop too but it is more work then a re-install ;)) – Rinzwind May 05 '12 at 20:23
  • Also, one should remove x11 cruft too afterwards with sudo apt-get remove x11* – Rob K Jul 30 '12 at 10:53

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,155
  • 1
    A clean install is the way to go, but if you want to manually remove packages, run dpkg --get-selections "*" >~/applications.txt and delete what you know you don't need. – tinker Jul 29 '10 at 01:48
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,264
  • 56
  • 94
  • 147
Alvar
  • 17,058
  • 1
    Well I removed ubuntu-desktop, but it did nothing, since no packages depends on it. I then removed all the packages that ubuntu-desktop depends on, which works better, but it still leaves a bit of a mess with packages like unity-common, gedit-common, etc. – Bart van Heukelom May 05 '12 at 19:00
  • @BartvanHeukelom well, did you purge it or just remove it? edited the question. – Alvar May 05 '12 at 20:25
  • 1
    iirc sudo apt-get remove gnome-* would take care of most packages. Unity should be removed alongside this (cuz of dependencies). (needs confirmation though since I tend to not do this) – Rinzwind May 05 '12 at 20:27
  • I removed it (accidentally), didn't purge, but AFAIK that shouldn't matter regarding dependencies. – Bart van Heukelom May 07 '12 at 08:49
  • @BartVanHeukelom did you try Rinzwind's command? sudo apt-get remove gnome-*? – Alvar May 07 '12 at 09:19
  • I already removed all gnome packages pseudo-manually before it was posted. Anyway, I seem to have broken the system now, so I'm just going to reinstall with the server version :P – Bart van Heukelom May 07 '12 at 13:17
  • @BartVanHeukelom it's always better to make a fresh install. everything will go smoother and less risk of getting a broken install. But I understand, people are lazy, so am I... – Alvar May 07 '12 at 16:12
  • @Bart @Rinzwind @Alvar when I try to remove gnome-*, apt-get notifies that it is about to install a whole set of new packages, including kde (!) as a result. Could it be that the installation insists on having either gnome or kde? – GJ. May 29 '12 at 19:24
  • 2
    Since 12.04, there is no difference in kernel between Ubuntu Desktop and Ubuntu Server since linux-image-server is merged into linux-image-generic. (from Ubuntu ServerFaq) – Amir Ali Akbari Jan 02 '14 at 12:37
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,744
  • 1
    Can you or someone else confirm this works? You say try, but if it does work this is a great answer. – djeikyb May 29 '12 at 20:01
  • 1
    Excerpt from Ubuntu Tasksel page: WARNING: Use tasksel only to install tasks, never to remove any! According to https://launchpad.net/bugs/574287 it will remove each package in the list of that task (and possibly render your system unusable). – Andrejs Cainikovs May 29 '12 at 20:12
  • As per above, I don't recommend you to use tasksel in your case. – Andrejs Cainikovs May 29 '12 at 20:13
  • 1
    @djeikyb i tried this with ubuntu 9.10 and ubuntu 11.10, and both work (wubi install, remove desktop and installing "server packages"). In 11.10 there's a small glitch: the system boots but dont shows you the login prompt. – Salem May 30 '12 at 10:27
  • @AndrejsCainikovs i only used tasksel with this specific task (remove desktop -> install server) and in the systems i used it works. I will update the answer – Salem May 30 '12 at 10:40
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