Debian – How to remove all packages related to gui in Debian

chrootdebianguix11

I'm using Debian in a chroot environment on my android. As I don't use GUI at all, I think it's better to uninstall packages related to GUI to free up space.

  1. What can I do to remove all GUI packages?
  2. How can I reinstall all those removed packages, if anything breaks
    after the package removal?(optional)

As a response to @Arpit Agarwal's comment, here's a link to debian installation procedure on android.
debian on termux

output of apt purge libx11-6 libwayland-client0:

Reading package lists...
Building dependency tree...
Reading state information...
Package 'libwayland-client0' is not installed, so not removed
The following packages were automatically installed and are no longer required:
  aglfn fontconfig fontconfig-config fonts-dejavu-core fonts-droid-fallback
  fonts-liberation fonts-noto-mono ghostscript gnuplot-data gsfonts
  hicolor-icon-theme imagemagick-6-common info java-common krb5-locales
  libaec0 libamd2 libarpack2 libasound2 libasound2-data libauthen-sasl-perl
  libavahi-client3 libavahi-common-data libavahi-common3 libblas-common
  libblas3 libcamd2 libccolamd2 libcholmod3 libcolamd2 libcups2
  libcupsfilters1 libcupsimage2 libcurl3-gnutls libcxsparse3 libdatrie1
  libdjvulibre-text libdjvulibre21 libdrm-amdgpu1 libdrm-freedreno1
  libdrm-nouveau2 libdrm-radeon1 libdrm2 libedit2 libencode-locale-perl
  libfftw3-double3 libfftw3-single3 libfile-listing-perl libflac8
  libfont-afm-perl libfontconfig1 libfreetype6 libgdk-pixbuf2.0-common
  libgfortran3 libgl1-mesa-dri libglapi-mesa libglib2.0-0 libglib2.0-data
  libglpk40 libgraphite2-3 libgs9 libgs9-common libgssapi-krb5-2 libharfbuzz0b
  libhdf5-100 libhtml-form-perl libhtml-format-perl libhtml-parser-perl
  libhtml-tagset-perl libhtml-tree-perl libhttp-cookies-perl
  libhttp-daemon-perl libhttp-date-perl libhttp-message-perl
  libhttp-negotiate-perl libice6 libijs-0.35 libilmbase12 libio-html-perl
  libio-socket-ssl-perl libjack-jackd2-0 libjbig0 libjbig2dec0 libjpeg62-turbo
  libjxr-tools libjxr0 libk5crypto3 libkeyutils1 libkrb5-3 libkrb5support0
  liblapack3 liblcms2-2 libldap-2.4-2 libldap-common libllvm3.9 liblqr-1-0
  libltdl7 liblua5.1-0 liblwp-mediatypes-perl liblwp-protocol-https-perl
  libmailtools-perl libmetis5 libmng1 libnet-http-perl libnet-smtp-ssl-perl
  libnet-ssleay-perl libnetpbm10 libnghttp2-14 libnspr4 libnss3 libogg0
  libopenblas-base libopenexr22 libopenjp2-7 libopus0 libosmesa6
  libpango-1.0-0 libpangoft2-1.0-0 libpaper-utils libpaper1 libpcsclite1
  libpixman-1-0 libpng16-16 libportaudio2 libqhull7 libqrupdate1
  libqscintilla2-l10n libqt4-dbus libqt4-network libqt4-xml libqtcore4
  libqtdbus4 librtmp1 libsamplerate0 libsasl2-2 libsasl2-modules
  libsasl2-modules-db libsensors4 libsm6 libsndfile1 libssh2-1
  libsuitesparseconfig4 libsz2 libtext-unidecode-perl libthai-data libthai0
  libtiff5 libtimedate-perl libtxc-dxtn-s2tc libumfpack5 liburi-perl
  libvorbis0a libvorbisenc2 libwebp6 libwww-perl libwww-robotrules-perl
  libx11-data libx11-xcb1 libxau6 libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0
  libxcb-present0 libxcb-render0 libxcb-shm0 libxcb-sync1 libxcb1 libxdmcp6
  libxml-libxml-perl libxml-namespacesupport-perl libxml-parser-perl
  libxml-sax-base-perl libxml-sax-expat-perl libxml-sax-perl libxshmfence1
  libzip4 netpbm octave-common octave-info perl-openssl-defaults poppler-data
  psutils qdbus qtchooser qtcore4-l10n shared-mime-info tex-common texinfo ucf
  x11-common xdg-user-dirs
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
  ca-certificates-java* default-jre-headless* gnuplot-nox* groff* imagemagick*
  imagemagick-6.q16* libaudio2* libcairo2* libfltk-gl1.3* libfltk1.3* libgd3*
  libgdk-pixbuf2.0-0* libgl1-mesa-glx* libgl2ps1* libglu1-mesa*
  libgraphicsmagick++-q16-12* libgraphicsmagick-q16-3* libmagick++-6.q16-7*
  libmagickcore-6.q16-3* libmagickcore-6.q16-3-extra* libmagickwand-6.q16-3*
  liboctave3v5* libpangocairo-1.0-0* libplot2c2* libpstoedit0c2a*
  libqscintilla2-12v5* libqt4-opengl* libqtgui4* libwmf0.2-7* libx11-6*
  libxaw7* libxcursor1* libxdamage1* libxext6* libxfixes3* libxft2* libxi6*
  libxinerama1* libxmu6* libxpm4* libxrender1* libxt6* libxtst6* libxxf86vm1*
  octave* openjdk-8-jre-headless* pstoedit* qt-at-spi*

Need some suggestions regarding which packages can be removed safely without affecting Octave. Otherwise this question can be closed , if the some specific answer can't be given.

Best Answer

On Debian, to remove all GUI packages, you can remove the two libraries used to connect to display servers:

apt purge libx11-6 libwayland-client0

This will remove all packages depending on these libraries. The removals will be logged in the history logs in /var/log/apt, so you can look there if you need to revert a removal.

This might catch some packages which contain both CLI and GUI tools, although in most, if not all, cases those are packaged separately (so that it is possible to have a functional text-only system).

Related Question