I'm using my Raspberry Pi as a headless server which I can ssh into. I don't need the X Server, LXDE etc.

I'm running Raspbian "wheezy". I've already disabled "Start desktop on boot" using raspi-config as described here. But I keep getting lots of package updates for all the desktop stuff that I don't use (I run apticron to notify me of pending updates via email), so I'd like to completely apt-get remove all the unnecessary packages to avoid these unnecessary updates.

Which package(s) should I remove?

So far, I've come up with the following:

sudo apt-get remove desktop-base lightdm lxappearance lxde-common lxde-icon-theme lxinput lxpanel lxpolkit lxrandr lxsession-edit lxshortcut lxtask lxterminal obconf openbox raspberrypi-artwork xarchiver xinit xserver-xorg xserver-xorg-video-fbdev

I made the above list by looking in aptitude for all packages in the Installed Packages -> x11 -> main section that were not "automatic installs".

For some reason when I run this, apt-get tells me that:

The following extra packages will be installed:
  libutempter0 xbitmaps xterm

which seems a little odd for a remove operation.

Is there an easier way? Is there a "super" package which owns all of this graphical stuff and can be removed, taking all it's dependencies with it? From my understanding, it doesn't look like this is possible, because these things have not been automatically installed, meaning I need to track them all down and remove them all explicitly.

8 Answers 8


TL;DR or "Just scorch my pi"

sudo apt-get remove --auto-remove --purge 'libx11-.*'
sudo apt-get autoremove --purge

(Repeat apt-get autoremove --purge until no orphans remain)

Further explanation

If a package foo depends on another package libfoo and you remove the libfoo package, the dependent (foo) is also removed. Because Foo has a depends line specifying libfoo, it would be broken to leave foo if libfoo were removed. The reverse is not true: removing foo does not delete libfoo automatically. Another package xfoo may also depend upon libfoo, so apt won't just remove it (although apt will track if it was installed only as a side-effect of installing foo and offer to auto-remove it if you ask it to, so long as no others still depend on it)

Meta packages depend on a set of other packages in much the same way that foo depended on libfoo, so when you remove a meta-package, little else is typically removed. For example, there may be two meta-packages that depend on xterm (lxsession and xfsession perhaps), but uninstalling one or both won't uninstall xterm because xterm isn't broken without lxsession or xfsession. Meta-packages are generally at the top of the dependency tree, not at the bottom, and few things tend to depend directly on meta-packages. Meta-packages primarily provide a convenient way to install a sensible set of packages at once, but they aren't uninstall tools.

So, if you want to scorch everything that depends upon X11, you will need to target the base set of libx11 libraries that all x11 apps must ultimately depend upon:

sudo apt-get remove --dry-run --auto-remove --purge 'libx11-.*'
sudo apt-get autoremove --dry-run --purge

This will (simulate) remove everything that ultimately depends on libx11-.*, and will also remove any packages that were installed as a dependency of an X11 program even if they didn't directly depend on X11 itself (CUPS and Ghostscript are typically installed as a side-effect of installing a desktop environment). The second command will remove subsequent orphans until none remain. Remove "--auto-remove" if you want to do this step later or not do it at all, or just add back the packages manually after cleaning the GUI off.

Remove the --dry-run option to actually perform the operation after you have checked that it won't remove packages you did not intend to be removed.)

I prefer to clean and purge the side-effects, and add them back as needed. Also, I went ahead and tested this on my own pi, and it rebooted to a very spartan but functional server. :)

Why does a remove install something?

The above strategy solves the stated problem, but there is still the curiosity of why a remove operation results in packages being installed.

At the heart of every package manager is a satisfiability solver of some kind. When you tell a package manager to install some packages, remove some packages, or upgrade some packages, what you are really asking it to do is to solve for the next desired state of software installation given an available set of packages. This solution may include installing additional packages (dependencies), removing existing packages (conflicts, breaks), downgrading/upgrading specific packages (compatibility level), or a combination thereof. So, while it is a bit counterintuitive that the solver determines that some packages need to be installed in order for other packages to be removed, it makes perfect sense. This is the nasty dependency management problem that package managers solve.

A concrete example: Given a set of Java applications already installed, they all depend upon a java compatible runtime which currently happens to be openjdk-7-jre. You then ask the package manager to solve for installation of a new Java tool that declares a conflict with openjdk-7-jre but works with oracle-7-jre (both packages generically provide a java-7-runtime). The solver will propose a removal of openjdk-7-jre and an install of oracle-java-7-jre as the solution to your desired state of having the new package installed while not breaking existing packages.

In this specific case, xterm is a package that provides a virtual dependency called x-terminal-emulator (xterm, lxterminal, and aterm all provide an x-terminal-emulator), so it is likely that in removing lxterminal (as a part of removing lxde), the solver found an existing installed package (transcode as a possible example) that required some kind of x-terminal-emulator, so the solver chose to install xterm (which requires libutempter0 and xbitmaps, explaining the other packages to install) to satisfy the otherwise broken dependency. Without seeing the package database, I would hypothesize that this is the most likely scenario.

To discover the packages that are currently depending upon xterm (or an alternate), use the apt-cache rdepends command (using the --installed switch to limit to installed packages only):

$ apt-cache --installed rdepends xterm
Reverse Depends:

Dependencies that start with the alternation character '|' mean that the package depends on xterm or something it provides (that something is x-terminal-emulator in this case). The clusterssh package depends on xterm explicitly, and does not allow for an alternative. This is the short list of the packages that are causing xterm to be required.

What about deborphan?

The functionality of tracking orphans was incorporated into apt-get via the 'autoremove' functionality in 2010 (Debian bug 582791) rendering deborphan mostly redundant and essentially obsolete. Unlike deborphan and other solutions like it, apt-get directly tracks which packages were explicitly installed and which packages were installed as a side-effect or dependency of an explicitly installed package. For example, if an administrator installs foo, libfoo is installed as a side-effect and apt-get autoremove will, in fact, remove libfoo if autoremove (or --auto-remove) is specified when removing foo.

The approach taken by deborphan is a collection of guesses. For example, the guess that an installed library that does not have a dependent must be an orphan: If libfoo is installed, but neither foo nor xfoo are, deborphan may decide it must be an orphan. One failure mode here is that libraries might be specifically installed for the tools they provide (libxml2 for xmllint before it was repackaged into libxml2-utils) or simply available for development purposes. Such packages are not orphans. Additionally, deborphan focuses on libraries, so it misses a number of non-library orphans that apt tracks (Obsolete packages vs. orphaned packages).

  • 2
    Brilliant worked for me thanks. It did also remove munin for some reason, but I could put that back easily enough afterwards.
    – Day
    Mar 11, 2013 at 12:53
  • 4
    Scorch it! I had to quote 'libx11-.*' to prevent the shell from globbing.
    – user9091
    Aug 18, 2013 at 20:16
  • 1
    @Maxx, great answer, but in all your scenarios, you didn't describe how it is that when he ran the apt-get remove that it wanted to install xterm and two others. I too have experienced this and couldn't work it out.
    – Madivad
    Aug 25, 2013 at 11:17
  • 2
    Clean, unexpanded raspbian install, after apt-get upgrade, dist-upgrade: rootfs ... 94% /. After apt-get remove --auto-remove --purge libx11-.*: rootfs ... 51% / Excellent answer, thanks so much!
    – Daniel F
    Feb 1, 2015 at 20:16
  • 2
    And after apt-get autoremove: rootfs ... 41% /...
    – Daniel F
    Feb 1, 2015 at 20:36
sudo apt-get install deborphan
sudo apt-get autoremove --purge libx11-.* lxde-.* raspberrypi-artwork xkb-data omxplayer penguinspuzzle sgml-base xml-core alsa-.* cifs-.* samba-.* fonts-.* desktop-* gnome-.*
sudo apt-get autoremove --purge $(deborphan)
sudo apt-get autoremove --purge
sudo apt-get autoclean

The first line installs deborphan which will remove any orphaned packages.

The second line removes the core packages of the X11 system LXDE, Samba (Windows File Sharing), fonts, Gnome, and other stuff related to the Raspberry Pi's desktop environment.

The third line removes any orphaned packages detected by deborphan.

The fourth line removes any unneeded packages.

The fifth line clears the package cache.

  • 3
    Welcome to Raspberry Pi Stack Exchange! While this may technically answer the question, it would be preferable to include some explanation of how this works and what exactly it's doing. Sep 11, 2014 at 16:41
  • 1
    Running those commands on brand new Raspbian install I went from less than a gigabyte free on a 4GB SD card to 2.5GB free. To me at least this is the correct answer.
    – rob
    Jan 18, 2015 at 15:58
  • 3
    The accepted answer is very in-depth but it doesn't actually give a list to accomplish OP's problem. This answer may be barebones, but it actually accomplishes what OP (and me) actually need
    – benathon
    Apr 5, 2015 at 2:39
  • 3
    Why uninstall samba? This isn't a GUI application. Might be necessary for networking.
    – Dogweather
    Oct 8, 2018 at 8:54

Have a look here but scroll down to the part about tasksel.

Running tasksel --list-tasks on the pi via wifi ssh gives me (after about 30 seconds):

u desktop   Debian desktop environment
u web-server    Web server
u print-server  Print server
u database-server   SQL database
u dns-server    DNS Server
u file-server   File server
u mail-server   Mail server
u ssh-server    SSH server
u laptop    Laptop

So, tasksel remove desktop should do what you want [see comments]. The man page is a little brief and mysterious, perhaps because tasksel is mostly intended for debian maintainers. If this works let us know ;)

  • Thanks, I'd never heard of tasksel, although I do have a fair amount of Ubuntu experience. Unfortunately I tried this, it took a while to run the remove desktop command but all those "graphical" packages are still there according to aptitude.
    – Day
    Jan 29, 2013 at 20:39
  • I hadn't either, but I was a little perturbed when I noticed just apt removing some basic X component did not pull the whole dependency stack, which I thought it would. I found a better page for tasksel, and actually fired up the ncurses app (tasksel with no options). Pretty sure now the 'u' means the metapackages are't installed, and if you install 'desktop', you will get a get more than just the lxde version wiki.debian.org/tasksel So no dice. I notice the "xorg" metapackage from apt-cache search metapackage is not actually installed either. Blame the raspbians I guess.
    – goldilocks
    Jan 29, 2013 at 20:54
  • 2
    I'll leave this answer up to save someone a dead end, or in case anyone can shed better light.
    – goldilocks
    Jan 29, 2013 at 20:56

1/. To remove all desktops I just did (go make a pot of coffee. Take a walk this will take a while)...
apt-get remove --auto-remove --purge libx11-.*

2/. Then I installed deborphan to get rid of orphaned files...
sudo apt-get install deborphan

If you want to see what has been orphaned do this...
deborphan -sz

3/. Then I removed all orphaned files...
sudo apt-get remove --purge $(deborphan)

Finally do this to remove the unnecessary packages that are not orphaned...
sudo apt-get autoremove

Final result: Headless and clean as a whistle

  • 2
    apt-get remove --dry-run does absolutely nothing, but prints messages on the screen.
    – lenik
    Jun 16, 2014 at 4:26

Alternatively, you can try this Raspbian minimal image: http://www.linuxsystems.it/raspbian-wheezy-armhf-raspberry-pi-minimal-image/

  • 4
    Doesn't answer the question at all. The question was how to uninstall X, not how to install a new OS without X. This would have best been left as a comment, try asking your own question or providing a useful answer to get the rep needed to leave a comment. Nice link none the less.
    – Impulss
    Nov 20, 2013 at 2:49

Based on the tasksel information, it is possible to find out, that there is a meta-package task-desktop, which references all the other GUI related packages. So just

sudo apt-get remove task-desktop

This will remove plenty of other packages (GUI/Desktop related).

Background: name of the package task-desktop can be found by running following tasksel commands:

tasksel --list-tasks
tasksel --task-packages desktop

Another option is to use aptitude which you should always prefer, if you're going to do more than just install or remove a few packages.

Start aptitude as root by typing sudo aptitude. In the standard Packages view of aptitude the last list entry is Tasks in which you can select the various options listed by tasksel. Navigate through the items with j, k and enter. Mark an item to be purged by entering _ (underscore) on the highlighted item. This only prepares actions. To execute the actions press g.

Read about aptitude in the debian manual.


Type this code:

sudo apt-get purge desktop-base lightdm lxappearance lxde-common lxde-icon-theme lxinput lxpanel lxpolkit lxrandr lxsession-edit lxshortcut lxtask lxterminal obconf openbox raspberrypi-artwork xarchiver xinit xserver-xorg xserver-xorg-video-fbdev
  • 1
    So, to clarify, the only difference between the OP's command line and yours, is the use of purge en lieu of remove? Feb 7, 2016 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.