sudo systemctl stop snapd && sudo systemctl disable snapd
# Workaround for https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1998710
# This command is needed starting from Ubuntu 22.10
# Without it an error is returned when running the snapd purge command
# In that case you need to reinstall snapd to cleanly remove it in a second attempt
snap remove microk8s --purge
# purge snapd
sudo apt purge snapd
# remove no longer needed folders
rm -rf ~/snap
sudo rm -rf /snap /var/snap /var/lib/snapd /var/cache/snapd /usr/lib/snapd /root/snap
snap install microk8s --classic --channel=1.31