An old laptop or mini PC with a full desktop install makes a fine little server, but then the desktop starts at every boot and eats memory for nobody. You don’t have to uninstall anything to stop that. You only change the target systemd boots into.
First see what it boots into now:
systemctl get-default
A desktop system answers graphical.target. A server wants multi-user.target, the non-graphical, multi-user state with networking and all your services:
sudo systemctl set-default multi-user.target
Under the hood this only points the default.target symlink at a different target. Nothing is removed, and since graphical.target pulls in multi-user.target anyway, every service that ran before still runs; only the display manager and the desktop session stay off. After the next reboot you get a text login, and SSH works as before. Changed your mind? sudo systemctl set-default graphical.target brings the desktop back on the next boot.
The caveat is about doing it right now instead of after a reboot. systemctl isolate multi-user.target switches immediately, but it stops every unit that isn’t part of the new target, and the systemctl manual calls it dangerous because that can include the graphical session or terminal you are typing in. If you’re logged in on that desktop, save your work first, or simply reboot. And if you need the desktop once in a while, sudo systemctl start graphical.target starts it for one session without changing the default.
Further reading: systemctl(1) manual page, systemd.special(7) manual page