2

I want to make my Debian server cleaner, easier to manage, and have better performance. Is there a command that I can run to clean up (uninstall) all non essential packages so that I can start from the bare minimum and just install what I need thereafter?

I've already read the threads below, but haven't found what I'm looking for

5 Answers 5

8

Is there a command that I can run to clean up (uninstall) all non essential packages

No, since "non-essential" is hugely subjective. If you mean, the bare minimum to have a running system, then that wouldn't include things that make it a "server". If you mean, just the bare minimum plus whatever you need to make it a server, this begs the question, "What kind of server?". Is sshd essential? Etc.

Pulling it down to some theoretical bare minimum and then adding whatever you want back in will be more trouble than just removing the things you know you do not want. However, if you are really dedicated to this approach, you are better off starting with Arch than Raspbian. Beware that it is aimed at more advanced/knowledgeable users.

have better performance

Removing packages that you are not using will not improve performance. The only thing it will do for you is free up some space. The base Raspbian install is less than 2 GB, but if you remove all the GUI stuff, you might free up 4-500 MB. Beyond that, there's not really much fat. If you try the minimal build with Arch, you will likely end up with 1 - 1.5 GB anyway.

Keep in mind that just because you do not understand what the purpose of something is does not mean it does not have one. Your concern is not unusual (I use to think this way, a long time ago), but it is not particularly rational, either. There are a lot of things you can do to tailor your system to your needs, but obsessive compulsive fixation on the of number of installed packages is not one of them.

6
  • -I'm looking to have just a pure ssh server, yeah. I noticed this article: wiki.debian.org/ReduceDebian#Remove_non-critical_packages -I am not a knowledgeable user so maybe Arch isn't a good idea :) -Surely different packages run different processes in the background, similarly to Windows? (Pure guess work). -Basically, I just bought a raspberry pi b+ and now I'm trying to use it as a server so I'm starting off by cleaning it up and securing it before I use it.
    – anon
    Jan 2, 2015 at 18:07
  • Background processes only exist because they are started by you (or something you used) or the init system, which happens at boot. Debian/raspbian uses SysV init, which you can read much about online. The default runlevel is I believe 2 or 3 (you can find this with runlevel), and the services that are started (or stopped) there are listed in /etc/rc2.d (or rc3.d; the ones starting with an S are started, K are killed). There may be some stuff there you don't need.
    – goldilocks
    Jan 2, 2015 at 18:19
  • 1
    ...There isn't really anything that's going to impede performance though; they're generally idle. You can also have a look at currently running processes with top (or the nicer htop, you would need to install that). Also, ps -lA. If there's something you think is pointless, it can be disabled via init with update-rc.d disable, see man update-rc.d for exact usage.
    – goldilocks
    Jan 2, 2015 at 18:20
  • but basically it's not possible to run a command that can just clean up (remove) non-critical packages for me?
    – anon
    Jan 2, 2015 at 18:24
  • 1
    ...to improve performance if available. Which is why it is a good idea on the pi to make sure at least 100 MB is left free (or in buffers/cache).
    – goldilocks
    Jan 2, 2015 at 18:30
5

While I fully agree with @goldilocks that being obsessive about the number of installed packages is pointless, there's one useful trick I want to share.

All packages in the system basically fall in two categories: auto and manual. manual packages are the ones that have been installed to provide a particular functionality, while auto packages were installed by the package manager automatically to satisfy dependencies of manual packages.

Knowing this, it's quite clear that uninstalling an auto package can't do you any good (I'm actually surprised aptitude allows this operation without displaying big warning signs), because you will inevitably end up removing packages you didn't plant to remove.

Sounds like removing manual packages is a good idea then? Actually, no: a manual package can still be required by other manual packages, so removing it directly may still result in removing something important you didn't plan to remove.

So, if you shouldn't remove neither auto nor manual packages, how do you remove anything at all? The answer is: you demote unwanted manual packages to auto, the use auto-remove to get rid of packages which are truly unnecessary:

apt-mark showmanual
# You'll get a list of "manual" packages. Suppose you don't want "foobar"
apt-mark auto foobar
apt-get autoremove

This will remove the package foobar (and all its dependencies which are not needed by anyone else), but only if foobar itself is not a dependency of a package you want to keep.

3

In his answer, goldilocks wrote “‘non-essential’ is hugely subjective”, and this is essentially correct. However, the package maintainers have their own idea of how important a package is, and this information is available in the package’s metadata as the priority field. The defined priorities are:

  • required: Packages which are necessary for the proper functioning of the system [...]
  • important: Important programs, including those which one would expect to find on any Unix-like system. [...]
  • standard: These packages provide a reasonably small but not too limited character-mode system. [...]
  • optional: This is all the software that you might reasonably want to install if you didn't know what it was and don't have specialized requirements. [...]
  • extra: This contains all packages that conflict with others with required, important, standard or optional priorities, or are only likely to be useful if you already know what they are or have specialized requirements [...]

For the full description of the priority levels (this is only an excerpt), see the Debian Policy Manual.

If you want to rely on this assessment of importance, you could use for example the following command to list the size and name of every optional and extra package on your system, sorted by size:

dpkg-query -Wf '${Installed-Size}\t${Package}\t${Priority}\n' | \
    egrep '\s(optional|extra)' | cut -f 1,2 | sort -nr | less

This command comes from the comment thread in “How To Free Up Some Space On Your Raspbian SD Card? Remove Wolfram & LibreOffice”. It can provide a list of candidates for removal. You can then inspect each package in the list (apt-cache show <package-name>) and decide whether you want to remove it or not.

The command above could be easily modified for automatically purging all the packages from the list, but I don't think it would be wise to do so.

Edit: To illustrate why it is unwise to automatically remove all packages listed as low priority, I just noticed this one in the latest Jessie Lite:

Package: raspberrypi-kernel
Provides: linux-image
Priority: extra
Description: Raspberry Pi bootloader
 This package contains the Raspberry Pi Linux kernel.
...

I cannot understand why it is listed as Priority: extra. I certainly would not want to remove it.

1
  • "extra" in case of a bootloader means "potentially conflicting". You will certainly not want to remove the bootloader you already have, but installing a second bootloader is likely to break the system just as well. Also note that most shared libraries are "optional", and you don't want to remove those either, so package priority alone is not really a good criteria for removal. Apr 7, 2021 at 15:21
0

My understanding is limited but growing. Why cant you just install a lite version of raspian with no extra software/apps. Use the CLI over GUI and then install only the packages you want for your server? I have one SD card that I have used this method it uses very little space and it only has packages I install personally. If I update or upgrade and something is no longer needed I am still notified and asked if I want to delete. Unless I am missing the point or misunderstand the question, I do not understand why this method wouldnt meet your needs.

1
  • Also as a warning, just assuming that a "magic" command to clean up or uninstall unnecessary packages would work if it existed is not realistic. I have used sudo auto clean and sudo autoremove and broke dependencies. I would never trust such a broad clean up package if it did indeed exsist
    – Pismurf
    May 14, 2017 at 16:28
-3

i use just
"$ aptitude install/remove [XXX]"
in root account (under root priveleges)!!!

and there is no common decision/solution because someone needs flexibility loses functionality and someone needs system functionality loses flexibility as non-essential means "native" - that is a really high subjective-valued character


[XXX] - package name / specified according to the situation

2
  • I guess what I'm searching for is a factory reset that strips it down to the absolute basics
    – anon
    Jan 2, 2015 at 19:25
  • Well, factory reset depends on your personal initial needs, so IMHO there is no factory reset... for example every server is naturally aimed to WEB-SERVER or FTP-server or... as a result - even LAN/WAN and other settings should be called FACTORY SETTINGS and could not be the same all over the world
    – dev.yii
    Jan 2, 2015 at 19:58

Your Answer

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