Remove X or create a headless server on a Raspberry Pi

As I use my Raspberry Pi as a headless server, I thought it would be a good idea to clean up unnecessary files. After studying some material from others and several attempts later, I distilled the following steps…

Login to your Raspberry Pi, so open a terminal and use SSH…

Step – 1: To get rid of orphaned files later, we are going to install a program called deborphan first:

sudo apt-get install deborphan

 

Step – 2: Next we are going to remove all desktops from your Raspbian (if you don’t want to remove samba, remove it from the following command!):

sudo apt-get remove –auto-remove –purge libx11-.* lxde-.* raspberrypi-artwork xkb-data omxplayer penguinspuzzle sgml-base xml-core cifs-.* samba-.* fonts-.* desktop-* gnome-.*

 

Step – 3: Now we are going to remove all orphaned files:

sudo apt-get remove –purge $(deborphan)

 

Step – 4: After that it is time to remove the unnecessary packages that are not orphaned:

sudo apt-get autoremove

 

Step – 5: You can even free up more space by removing the locales:

sudo apt-get install locale:purge:
sudo localepurge

 

Step – 6: Clean up some more:

sudo apt-get clean

 

Step – 7: You might need to reinstall the following packages for squeezelite:

sudo apt-get install -y libflac-dev libfaad2 libmad0

 

Step – 8: Reboot If you want, else stop start the service:

sudo shutdown -r now

 

By doing a “before and after“, you can see the difference:

df -h /dev/root

 

Suggestions for improving this article are welcome, please let me know and drop me a line .