Replace Snap with Flatpak on Ubuntu, Kubuntu, and Debian
Remove and Block Snap on Debian-Based Systems
de-snap.sh removes installed Snap packages and snapd, deletes remaining Snap data, and creates an APT pin that prevents snapd from being installed again.
This script has been tested on Ubuntu, Kubuntu, and Debian. Other Debian-based distributions may work, but they have not been tested.
Important warning
This script is intentionally destructive. It removes:
- All installed Snap packages
- The
snapdpackage - Snap data stored in
$HOME/snap - System Snap data under
/snap,/var/snap,/var/lib/snapd, and/var/cache/snapd
Back up any Snap application data you want to keep before running it. Removed application data cannot be recovered by reinstalling snapd.
The script does not automatically replace removed Snap applications with Debian packages or Flatpak applications.
What it does
The script:
- Detects the current Debian-based operating system.
- Removes installed Snap packages while the Snap daemon is still available.
- Stops and disables the remaining Snap services.
- Purges
snapdand unused dependencies. - Deletes remaining user and system Snap data.
- Creates
/etc/apt/preferences.d/nosnap.prefwith a negative APT priority. - Verifies that APT cannot select
snapdfor installation. - Installs Flatpak and adds the system-wide Flathub remote.
It is safe to run the script again after Snap has already been removed. The APT pin and Flathub remote are reapplied without creating duplicates.
Requirements
- Ubuntu, Kubuntu, Debian, or a similar Debian-based distribution
- A normal user account with
sudoaccess - An internet connection for updating APT metadata
- Bash
Usage
Download de-snap.sh, review it, and make it executable:
chmod +x de-snap.sh
Run it as your normal user:
./de-snap.sh
Do not run the entire script with sudo. It requests elevated privileges only for system-level changes.
Completing the removal
Reboot after the script finishes:
sudo reboot
This unloads any remaining Snap mounts and services from the current session.
Allowing snapd again
To remove the APT pin and allow snapd to be installed again:
sudo rm /etc/apt/preferences.d/nosnap.pref sudo apt-get update
You can then reinstall it if needed:
sudo apt-get install snapd
Removing the pin does not restore previously deleted Snap applications or their data.
Notes
Some distribution packages may expect or attempt to install snapd. With the pin active, those installations can fail until you choose a non-Snap package source or remove the pin.
Review the script and understand the removal paths before using it on an important system.
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| PIN_FILE="/etc/apt/preferences.d/nosnap.pref" | |
| if ((EUID == 0)); then | |
| echo "ERROR: Run this script as your normal user, not with sudo." >&2 | |
| echo "The script will request sudo only for system-level changes." >&2 | |
| exit 1 | |
| fi | |
| for command_name in apt-get dpkg-query sudo; do | |
| if ! command -v "$command_name" >/dev/null 2>&1; then | |
| echo "ERROR: Required command not found: $command_name" >&2 | |
| exit 1 | |
| fi | |
| done | |
| package_installed() { | |
| dpkg-query -W -f='${db:Status-Status}' "$1" 2>/dev/null \ | |
| | grep -q '^installed |