This Python script removes all disabled or old Snap packages from an Ubuntu-based system and restarts the snapd service to ensure proper operation.
If you find this project useful and would like to support its development, consider donating via PayPal or Venmo:
© 2025 Maulik Mistry
This project is licensed under the Apache License 2.0. See the LICENSE.txt file for full license text.
- Uses
subprocessfor secure command execution. - Automatically removes all disabled Snap revisions.
- Restarts
snapdservice and checks its status.
- Ensure Python 3 is installed.
- Save the script to a file, for example:
cleanup_snap_disabled.py. - Make the script executable: chmod +x cleanup_snap_disabled.py
- Run with: ./cleanup_snap_disabled.py
Note: This script requires sudo privileges since it modifies system-level Snap installations.
- https://people.ubuntu.com/~robert-ancell/snapd-glib/reference/SnapdClient.html
- https://gist.github.com/flexiondotorg/84c3f137d70f4e21ea46419833c0aff4
- https://forum.snapcraft.io/t/python-example-of-using-snapd-glib-to-authenticate-install-and-remove-snaps/2417
- https://forum.snapcraft.io/t/how-to-communicate-with-run-snapd-socket-using-python/6432/4
- https://stackoverflow.com/questions/13334634/the-difference-between-os-system-and-subprocess-calls