Ubuntu Desktop to Server

🚦 Boot to Basics & Silence the Updates

First disable automatic upgrades and disable the graphical login.

# Disable the automatic installation of security update
systemctl disable unattended-upgrades
# Sets the system to boot into a multi-user, non-graphical interface by default
systemctl set-default multi-user.target

🌟 Freshen Up!

Update de system

# Refreshes the list of available packages and their versions
# Upgrades all the packages
apt update && apt -y upgrade 

🔨 Snap Terminator

Firefox won’t uninstall clean with just the snap remove, so make sure it’s disabled fully and unmounted.

# Unmounts the file system mounted by snap for firefox
systemctl stop var-snap-firefox-common-host\\x2dhunspell.mount
# Disables the mount unit so that it won’t automatically
systemctl disable var-snap-firefox-common-host\\x2dhunspell.mount

🧹 Snap CleanSweep!

Remove all the snaps (Run 2 times!)

# snap list: Lists all installed Snap
# tail -n +2: Filters out the first line of the output from snap list
# awk '{ print $1; }': Extracts the first column from each line of the input, this first column represents the name of the Snap package
# for snap in $(...): This for-loop iterates over each Snap package name obtained from the previous commands.
# { snap remove --purge $snap; }: Inside the loop, this command removes each Snap package. The --purge option for all data and configuration files.
# snap list: Lists all installed Snap, maybe repeat for dependences
for snap in $( snap list | tail -n +2 | awk '{ print $1; }' ); { snap remove --purge $snap; } ; snap list

🔥 System Strip-Down

Purge all of the leftover desktop packages and dependencies

# apt purge ... -y: Remove packages and configuration files. The -y flag automatically answers "yes" to all prompts.
# Packages being removed include:
# ubuntu-desktop and ubuntu-desktop-minimal: These are meta-packages for the Ubuntu desktop environment.
# cups: The Common UNIX Printing System, used for managing printers.
# pipewire-bin: Executables related to the PipeWire media server, which handles audio and video streams.
# modemmanager: Software that manages modems.
# pulseaudio: A sound server for POSIX and Win32 systems.
# xdg-dbus-proxy: A proxy for D-Bus connections.
# wpasupplicant: Software for WPA/WPA2/WPA3 and other security standards in wireless networks.
# snapd: The package management system that handles the installation and management of snaps.
# avahi-autoipd and avahi-daemon: Services for facilitating network service discovery.
# firefox: The Firefox web browser.
# apt autoremove -y: Removes packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed.
# apt autoclean: Cleans up downloaded archive files (.deb) from the package cache that can no longer be downloaded and are largely useless.
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

Source