Score:0

Reset Ubuntu back to ubuntu-server pristine?

in flag

I've got an Ubuntu box that was running Ubuntu Desktop, and has been upgraded from 18.04 to 20.04 to 22.04.

I want to convert it into an Ubuntu Server.

What commands can I run to reset it (package-wise) to a pristine Ubuntu Server?

Note that this is not the same as simply uninstalling ubuntu-desktop (for which there are many answers on this site), since that leaves a load of other packages behind. For example: if at one point, I installed VLC, that includes some dependent GUI packages. I'd like to remove those (and VLC, e.g.) as well.

cn flag
The only quick and 100% accurate way is to re-install. I would delete the desktop, use `deborphan` or one of the other tools to remove traces of left over libraries and leave it at that.There is no need to back to "pristine".
in flag
That's a pity, 'cos it's running my K3s server node, and I don't particularly want to reinstall the rest of the cluster (keys would change, etc.).
guiverc avatar
cn flag
Only you know what exactly you changed in your system, what packages you installed etc & thus the best way to fix it. There is no prepared or intended way to do what you want, so you'll need to use *hacks* like what @popey has suggested in his good answer, and clean up any missed things yourself. Packages are created by different teams, with different agendas & none plan for what you want; so use your own plan, or use your data backups.
in flag
"Only you know what exactly you changed in your system" -- in theory, yes. But: I want to ignore this. What I want is: "get a list of the packages installed on this system; if they're not somewhere in ubuntu-server's dependency tree, remove them".
guiverc avatar
cn flag
The packages available on Ubuntu 22.04.2 LTS Server can be seen in the manifest (https://cdimage.ubuntu.com/releases/22.04/release/ubuntu-22.04.2-live-server-arm64.manifest) however the options used during install can result in not all packages being included; AND/OR as `subiquity` (the installer) upgrades prior to install (*if internet is available*) different packages can be downloaded/installed too. You'll have to ask the installer as to what options were selected.
Score:2
pl flag

There's a pretty quick and easy way to rip out almost everything graphical from an Ubuntu system, and thus revert back to a command-line only system. I've done this a few times, and it's been reliable. However, there might be the odd library or application left behind, but I'll show you how to remove those too.

The key part is to rip out underlying X11 library packages that the vast majority of your applications depend upon. I often just pick one, usually libxrender1.

However, depending on what you have installed, you may also need to remove libice6, libx11-6, libx11-data, libxau6, libxext6, libxdmcp6, libxi6, libxmuu1, libxpm4, libxtst6 and x11-common.

So, for example, below is what happens if you remove just one, but I'd probably recommend listing all the above too. It doesn't take long, and shouldn't remove anything other than graphical applications and libraries.

sudo apt autoremove libxrender

You'll find it will want to remove a lot of packages. I've just booted an old 20.04 VM here (which has some pending updates, so the output is a little different) but here's what you'll see - or similar.

$ sudo apt autoremove libxrender1
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  foomatic-filters printer-driver-foo2zjs printer-driver-foo2zjs-common python3-distupgrade ubuntu-release-upgrader-core
Suggested packages:
  hannah-foo2zjs psutils tix tk
Recommended packages:
  paps | cups | enscript | a2ps poppler-utils colord cups
The following packages will be REMOVED
  acl adwaita-icon-theme aisleriot apg apport apport-gtk apport-symptoms aptdaemon aptdaemon-data apturl apturl-common avahi-utils baobab bluez-cups bubblewrap cheese
  cheese-common colord colord-data cpp cpp-11 cups cups-browsed cups-core-drivers cups-daemon cups-filters cups-filters-core-drivers cups-ipp-utils cups-pk-helper
  cups-server-common dconf-cli deja-dup docbook-xml duplicity enchant-2 eog evince evince-common evolution-data-server evolution-data-server-common file-roller gcc-11-base
  gcr gdb gdm3 gedit gedit-common genisoimage geoclue-2.0 gir1.2-accountsservice-1.0 gir1.2-adw-1 gir1.2-atk-1.0 gir1.2-atspi-2.0 gir1.2-dbusmenu-glib-0.4 gir1.2-dee-1.0
  gir1.2-freedesktop gir1.2-gck-1 gir1.2-gcr-3 gir1.2-gdesktopenums-3.0 gir1.2-gdkpixbuf-2.0 gir1.2-gdm-1.0 gir1.2-geoclue-2.0 gir1.2-gnomebluetooth-3.0
  gir1.2-gnomedesktop-3.0 gir1.2-goa-1.0 gir1.2-graphene-1.0 gir1.2-gst-plugins-base-1.0 gir1.2-gstreamer-1.0 gir1.2-gtk-3.0 gir1.2-gtk-4.0 gir1.2-gtksource-4
  gir1.2-gudev-1.0 gir1.2-gweather-3.0 gir1.2-handy-1 gir1.2-harfbuzz-0.0 gir1.2-ibus-1.0 gir1.2-javascriptcoregtk-4.0 gir1.2-json-1.0 gir1.2-mutter-10 gir1.2-nm-1.0
  gir1.2-nma-1.0 gir1.2-notify-0.7 gir1.2-packagekitglib-1.0 gir1.2-pango-1.0 gir1.2-peas-1.0 gir1.2-polkit-1.0 gir1.2-rb-3.0 gir1.2-rsvg-2.0 gir1.2-snapd-1 gir1.2-soup-2.4
  gir1.2-totem-1.0 gir1.2-totemplparser-1.0 gir1.2-udisks-2.0 gir1.2-unity-7.0 gir1.2-upowerglib-1.0 gir1.2-vte-2.91 gir1.2-webkit2-4.0 gir1.2-wnck-3.0 gjs gkbd-capplet
  gnome-bluetooth gnome-bluetooth-3-common gnome-bluetooth-common gnome-calculator gnome-calendar gnome-characters gnome-control-center gnome-control-center-faces
  gnome-desktop3-data gnome-disk-utility gnome-font-viewer gnome-initial-setup gnome-keyring gnome-keyring-pkcs11 gnome-logs gnome-mahjongg gnome-mines gnome-online-accounts
  gnome-power-manager gnome-remote-desktop gnome-session-bin gnome-session-canberra gnome-session-common gnome-settings-daemon gnome-settings-daemon-common gnome-shell
  gnome-shell-common gnome-shell-extension-appindicator gnome-shell-extension-desktop-icons-ng gnome-shell-extension-ubuntu-dock gnome-startup-applications gnome-sudoku
  gnome-system-monitor gnome-terminal gnome-terminal-data gnome-themes-extra gnome-themes-extra-data gnome-todo gnome-todo-common gnome-user-docs gnome-video-effects
  grilo-plugins-0.3-base gstreamer1.0-clutter-3.0 gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-pipewire gstreamer1.0-plugins-base gstreamer1.0-plugins-good
  gstreamer1.0-pulseaudio gstreamer1.0-x gtk-update-icon-cache gtk2-engines-murrine gtk2-engines-pixbuf guile-2.2-libs hicolor-icon-theme hplip hplip-data
  humanity-icon-theme hunspell-en-us ibus ibus-data ibus-gtk ibus-gtk3 ibus-gtk4 ibus-table iio-sensor-proxy ipp-usb language-selector-gnome libaa1 libabsl20210324
  libabw-0.1-1 libadwaita-1-0 libatkmm-1.6-1v5 libatomic1 libavahi-ui-gtk3-0 libavc1394-0 libayatana-appindicator3-1 libayatana-ido3-0.4-0 libayatana-indicator3-7
  libbabeltrace1 libboost-filesystem1.74.0 libboost-iostreams1.74.0 libboost-locale1.74.0 libboost-regex1.74.0 libboost-thread1.74.0 libc6-dbg libcaca0 libcairo-gobject-perl
  libcairo-gobject2 libcairo-perl libcairo-script-interpreter2 libcairo2 libcairomm-1.0-1v5 libcamel-1.2-63 libcanberra-gtk3-0 libcanberra-gtk3-module libcanberra-pulse
  libcanberra0 libcdparanoia0 libcdr-0.1-1 libcheese-gtk25 libcheese8 libclucene-contribs1v5 libclucene-core1v5 libclutter-1.0-0 libclutter-1.0-common libclutter-gst-3.0-0
  libclutter-gtk-1.0-0 libcogl-common libcogl-pango20 libcogl-path20 libcogl20 libcolamd2 libcolord-gtk1 libcolord2 libcolorhug2 libcue2 libcupsimage2 libdatrie1
  libdazzle-1.0-0 libdazzle-common libdbusmenu-glib4 libdbusmenu-gtk3-4 libdebuginfod-common libdebuginfod1 libdee-1.0-4 libdjvulibre-text libdjvulibre21
  libdmapsharing-3.0-2 libdrm-amdgpu1 libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libdv4 libe-book-0.1-1 libebackend-1.2-10 libebook-1.2-20 libebook-contacts-1.2-3
  libecal-2.0-1 libedata-book-1.2-26 libedata-cal-2.0-1 libedataserver-1.2-26 libedataserverui-1.2-3 libegl-mesa0 libegl1 libenchant-2-2 libeot0 libepoxy0 libepubgen-0.1-1
  libetonyek-0.1-1 libevdocument3-4 libevent-2.1-7 libevview3-3 libexempi8 libexiv2-27 libexttextcat-2.0-0 libextutils-depends-perl libffi7 libfontembed1 libfontenc1
  libfreehand-0.1-1 libfreerdp-client2-2 libfreerdp-server2-2 libfreerdp2-2 libgail-common libgail18 libgbm1 libgc1 libgcr-ui-3-1 libgdm1 libgee-0.8-2 libgeoclue-2-0
  libgeocode-glib0 libgexiv2-2 libgif7 libgjs0g libgl1 libgl1-amber-dri libgl1-mesa-dri libglapi-mesa libgles2 libglib-object-introspection-perl libglib-perl
  libglibmm-2.4-1v5 libglu1-mesa libglvnd0 libglx-mesa0 libglx0 libgnome-autoar-0-0 libgnome-bg-4-1 libgnome-bluetooth-3.0-13 libgnome-bluetooth13 libgnome-desktop-3-19
  libgnome-desktop-4-1 libgnome-games-support-1-3 libgnome-games-support-common libgnome-todo libgnomekbd-common libgnomekbd8 libgoa-backend-1.0-1 libgom-1.0-0 libgpgmepp6
  libgpod-common libgpod4 libgraphene-1.0-0 libgraphite2-3 libgrilo-0.3-0 libgsf-1-114 libgsf-1-common libgsound0 libgspell-1-2 libgspell-1-common libgssdp-1.2-0
  libgstreamer-gl1.0-0 libgstreamer-plugins-good1.0-0 libgtk-3-0 libgtk-3-bin libgtk-3-common libgtk-4-1 libgtk-4-bin libgtk-4-common libgtk2.0-0 libgtk2.0-bin
  libgtk2.0-common libgtk3-perl libgtkmm-3.0-1v5 libgtksourceview-4-0 libgtksourceview-4-common libgtop-2.0-11 libgtop2-common libgupnp-1.2-1 libgupnp-av-1.0-3
  libgupnp-dlna-2.0-4 libgweather-3-16 libgweather-common libgxps2 libhandy-1-0 libharfbuzz-icu0 libharfbuzz0b libhpmud0 libhunspell-1.7-0 libhyphen0 libibus-1.0-5
  libiec61883-0 libieee1284-3 libimagequant0 libinput-bin libinput10 libipt2 libisl23 libjavascriptcoregtk-4.0-18 libkpathsea6 liblirc-client0 libllvm15 liblouisutdml-bin
  liblouisutdml-data liblouisutdml9 liblua5.3-0 libmanette-0.2-0 libmediaart-2.0-0 libmessaging-menu0 libmhash2 libminiupnpc17 libmozjs-91-0 libmp3lame0 libmpc3 libmpfr6
  libmpg123-0 libmspub-0.1-1 libmtdev1 libmutter-10-0 libmwaw-0.3-3 libmythes-1.2-0 libnatpmp1 libnautilus-extension1a libnma-common libnma0 libodfgen-0.1-1 libopengl0
  liborcus-0.17-0 liborcus-parser-0.17-0 libpagemaker-0.0-0 libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libpangomm-1.4-1v5 libpangoxft-1.0-0 libpciaccess0
  libpeas-1.0-0 libpeas-common libphonenumber8 libpipewire-0.3-0 libpipewire-0.3-common libpipewire-0.3-modules libpkcs11-helper1 libpoppler-cpp0v5 libpoppler-glib8
  libpoppler118 libprotobuf23 libpulse-mainloop-glib0 libqpdf28 libqqwing2v5 libraptor2-0 libraqm0 librasqal3 libraw1394-11 libraw20 librdf0 libreoffice-base-core
  libreoffice-calc libreoffice-core libreoffice-draw libreoffice-gnome libreoffice-gtk3 libreoffice-impress libreoffice-math libreoffice-ogltrans libreoffice-pdfimport
  libreoffice-writer librest-0.7-0 librevenge-0.0-0 librhythmbox-core10 librsvg2-2 librsvg2-common librsync2 librygel-core-2.6-2 librygel-db-2.6-2 librygel-renderer-2.6-2
  librygel-server-2.6-2 libsane-common libsane-hpaio libsane1 libsensors-config libsensors5 libsgutils2-2 libshout3 libsigc++-2.0-0v5 libsnmp-base libsnmp40 libsodium23
  libsoup-gnome2.4-1 libsource-highlight-common libsource-highlight4v5 libspa-0.2-modules libspectre1 libspeex1 libstartup-notification0 libsuitesparseconfig5 libsynctex2
  libsysmetrics1 libtag1v5 libtag1v5-vanilla libthai-data libthai0 libtheora0 libtotem-plparser-common libtotem-plparser18 libtotem0 libtracker-sparql-3.0-0 libtwolame0
  libunity-protocol-private0 libunity-scopes-json-def-desktop libunity9 libv4l-0 libv4lconvert0 libvisio-0.1-1 libvisual-0.4-0 libvncclient1 libvncserver1 libvorbisfile3
  libvpx7 libvte-2.91-0 libvte-2.91-common libvulkan1 libwacom-bin libwacom-common libwacom9 libwavpack1 libwayland-client0 libwayland-cursor0 libwayland-egl1
  libwayland-server0 libwebkit2gtk-4.0-37 libwebpdemux2 libwebpmux3 libwhoopsie-preferences0 libwinpr2-2 libwnck-3-0 libwnck-3-common libwoff1 libwpd-0.10-10 libwpg-0.3-3
  libwps-0.4-4 libxatracker2 libxaw7 libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-present0 libxcb-randr0 libxcb-render-util0
  libxcb-render0 libxcb-res0 libxcb-shape0 libxcb-shm0 libxcb-sync1 libxcb-util1 libxcb-xfixes0 libxcb-xkb1 libxcb-xv0 libxcomposite1 libxcursor1 libxcvt0 libxdamage1
  libxfixes3 libxfont2 libxft2 libxinerama1 libxkbcommon-x11-0 libxkbcommon0 libxkbfile1 libxkbregistry0 libxklavier16 libxmlsec1 libxmlsec1-nss libxmu6 libxrandr2
  libxrender1 libxres1 libxshmfence1 libxslt1.1 libxss1 libxv1 libxvmc1 libxxf86dga1 libxxf86vm1 libyajl2 libyelp0 lp-solve media-player-info mesa-vulkan-drivers
  mobile-broadband-provider-info mousetweaks mutter mutter-common nautilus nautilus-data nautilus-extension-gnome-terminal nautilus-share network-manager-gnome
  network-manager-openvpn network-manager-openvpn-gnome network-manager-pptp-gnome openvpn orca p11-kit p11-kit-modules patch pinentry-gnome3 pipewire pipewire-bin
  pipewire-media-session plymouth-label plymouth-theme-spinner poppler-utils power-profiles-daemon printer-driver-hpcups printer-driver-postscript-hp printer-driver-splix
  python3-apport python3-aptdaemon python3-aptdaemon.gtk3widgets python3-bcrypt python3-brlapi python3-cairo python3-certifi python3-chardet python3-cups python3-cupshelpers
  python3-dateutil python3-debconf python3-debian python3-defer python3-fasteners python3-future python3-gi-cairo python3-ibus-1.0 python3-idna python3-lib2to3
  python3-lockfile python3-louis python3-macaroonbakery python3-mako python3-markupsafe python3-monotonic python3-nacl python3-olefile python3-paramiko python3-pexpect
  python3-pil python3-problem-report python3-protobuf python3-ptyprocess python3-pyatspi python3-pymacaroons python3-renderpm python3-reportlab python3-reportlab-accel
  python3-requests python3-rfc3339 python3-software-properties python3-speechd python3-systemd python3-tz python3-uno python3-urllib3 python3-xdg remmina remmina-common
  remmina-plugin-rdp remmina-plugin-secret remmina-plugin-vnc rhythmbox rhythmbox-data rhythmbox-plugin-alternative-toolbar rhythmbox-plugins rygel sane-airscan sane-utils
  seahorse sgml-base sgml-data shotwell shotwell-common simple-scan software-properties-common software-properties-gtk sound-theme-freedesktop spice-vdagent ssl-cert
  switcheroo-control system-config-printer system-config-printer-common system-config-printer-udev thunderbird thunderbird-gnome-support thunderbird-locale-en
  thunderbird-locale-en-gb thunderbird-locale-en-us totem totem-common totem-plugins tracker tracker-extract tracker-miner-fs transmission-common transmission-gtk
  ubuntu-advantage-desktop-daemon ubuntu-desktop ubuntu-desktop-minimal ubuntu-docs ubuntu-mono ubuntu-release-upgrader-gtk ubuntu-session unattended-upgrades update-manager
  update-notifier update-notifier-common usb-creator-common usb-creator-gtk whoopsie-preferences x11-apps x11-session-utils x11-utils x11-xkb-utils x11-xserver-utils
  xbitmaps xbrlapi xcvt xdg-dbus-proxy xdg-desktop-portal xdg-desktop-portal-gnome xdg-desktop-portal-gtk xdg-user-dirs-gtk xfonts-base xfonts-encodings xfonts-scalable
  xfonts-utils xinit xinput xml-core xorg xorg-docs-core xserver-common xserver-xephyr xserver-xorg xserver-xorg-core xserver-xorg-input-all xserver-xorg-input-libinput
  xserver-xorg-input-wacom xserver-xorg-legacy xserver-xorg-video-all xserver-xorg-video-amdgpu xserver-xorg-video-ati xserver-xorg-video-fbdev xserver-xorg-video-intel
  xserver-xorg-video-nouveau xserver-xorg-video-qxl xserver-xorg-video-radeon xserver-xorg-video-vesa xserver-xorg-video-vmware xwayland yaru-theme-gtk yelp yelp-xsl zenity
  zenity-common
The following NEW packages will be installed
  foomatic-filters
The following packages will be upgraded:
  printer-driver-foo2zjs printer-driver-foo2zjs-common python3-distupgrade ubuntu-release-upgrader-core
4 to upgrade, 1 to newly install, 720 to remove and 96 not to upgrade.
Need to get 964 kB of archives.
After this operation, 1,519 MB disk space will be freed.
Do you want to continue? [Y/n] 

You'll note GNOME, desktop applications and a ton of libraries all listed in there.

I do still have some snaps installed, so:

for s in firefox snapd-desktop-integration gnome-3-38-2004 gtk-common-themes  snap-store; do sudo snap remove --purge $s; done

This leaves core20, bare and snapd snaps on my system, which I may need for server snaps. YMMV.

Reboot, and all your graphical packages will be gone.

Artur Meinild avatar
vn flag
And afterwards, you could install the [`ubuntu-server`](https://packages.ubuntu.com/jammy/ubuntu-server) metapackage, if it's not already present - or hand-pick the utilities from it you need.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.