Source: https://www.technomancer.com/archives/789
# Do this as a root
# Install Ubuntu Server, after stopping unattended upgrades
systemctl disable unattended-upgrades
systemctl set-default multi-user.target
apt update && apt -y upgrade
apt install ubuntu-server
# Getting rid of Firefox snap
systemctl stop var-snap-firefox-common-host\\x2dhunspell.mount
systemctl disable var-snap-firefox-common-host\\x2dhunspell.mount
# Remove all snaps (repeat this until no snap is left)
for snap in $( snap list | tail -n +2 | awk '{ print $1; }' ); { snap remove --purge $snap; } ; snap list
# Purge all of the leftover desktop packages
# (Other desktop packages should also be removed manually)
apt purge ubuntu-desktop ubuntu-desktop-minimal \
cups pipewire-bin modemmanager pulseaudio \
xdg-dbus-proxy wpasupplicant snapd \
avahi-autoipd avahi-daemon \
firefox -y
apt autoremove -y
apt autoclean
# Reboot after this
systemctl reboot