Converting Ubuntu Desktop Install to Server

These procedures were performed/tested on Ubuntu Desktop 22 LTS. On other versions, YMMV.

I like to use ZFS on the root/boot volumes, however with Ubuntu (as of 22), you can only install it that way with the desktop installer. But that, of course, installs all the Desktop stuff I do not need on a server.

I found numerous places on the net that say that just doing an apt purge ubuntu-desktop and then an apt autoremove will remove the desktop stuff. It does not even come close. There are some other packages that are not really needed by a server. I went through all the processes still running, but were not needed to serve my application. Here is how I removed them:

First disable automatic upgrades. This is a bad thing on servers. Disable the graphical login (switching it to “multi-user” instead of graphical. Then make sure everything is up to date.

Install the ubuntu-server package.

systemctl disable unattended-upgrades
systemctl set-default multi-user.target

apt update && apt -y upgrade 

apt install ubuntu-server

Now you have all the server components, but you still have all the desktop clutter that can be purged.

First, we get rid of the whole snap system. Firefox won’t uninstall clean with just the snap remove, so make sure it’s disabled fully and unmounted:

systemctl stop var-snap-firefox-common-host\\x2dhunspell.mount
systemctl disable var-snap-firefox-common-host\\x2dhunspell.mount

Now to remove all the snaps. There are some dependencies here, so just re-run the loop until it shows no snaps installed:

for snap in $( snap list | tail -n +2 | awk '{ print $1; }' ); { snap remove --purge $snap; } ; snap list

Now we purge all of the leftover desktop packages, and all of the dependencies (if you installed kubuntu-desktop, or one of the other variants, you will need to adjust this accordingly):

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

It might complain that /var/snap is still in use; if you installed with ZFS on root, it will. You can ignore that. Once that has completed, just reboot to clear any remaining processes and now you have a server edition of Ubuntu.

shutdown -r now

Leave a Comment