Removing a snap package that was installed using the –purge flag can be a bit tricky compared to removing a regular snap package. The –purge flag removes the package configuration files and data along with the package itself. This means that simply running ‘snap remove [package]’ will not remove all traces of the package. Here are the steps to fully remove a snap package that was installed with –purge:
1. Remove the snap package
The first step is to remove the snap package itself using the snap remove command:
snap remove [package]
For example:
snap remove myapp
This will remove the main snap package but leave behind any configuration files and data.
2. Delete the package data directory
Snap packages keep their data in /var/snap/[package]/current. To delete the remaining data, you need to delete this directory. This can be done using rm:
sudo rm -rf /var/snap/myapp/current
This will recursively delete the /current data directory for the snap package.
3. Remove common data
Some snap packages share common data in /var/snap/common. To check if your package had any common data that needs deleting:
ls /var/snap/common | grep myapp
If this returns any directories related to your package, delete them with rm:
sudo rm -rf /var/snap/common/myapp
4. Remove configuration files
The last step is to remove any configuration files for the package. These are normally located in /var/snap/[package]/[version].
To find and delete any remaining configuration files:
sudo rm -rf /var/snap/myapp/*
This will remove all files and directories under /var/snap/myapp, including any version-specific configuration.
5. Restart snapd
After removing all package files, you may want to restart the snap daemon to fully clear things out:
sudo systemctl restart snapd
This will ensure snapd forgets about the removed snap package completely.
Conclusion
Removing a snap package installed with –purge requires manually deleting the package data directory, common data, configuration files, and restarting snapd. This will remove all traces of the package from the system.
The basic process is:
- Remove the package with
snap remove [package]
- Delete the /var/snap/[package]/current data directory
- Remove any common data for the package
- Delete configuration files under /var/snap/[package]
- Restart the snapd service
Following these steps will fully purge a snap package and its data after –purge was used to install it. This is useful for completely resetting a snap package.
Frequently Asked Questions
Why do I need to manually delete the data if I used –purge to install?
The –purge flag only removes data when first installing the package. After installation, snap remove will not remove the package data directory even if –purge was initially used. This means you have to manually delete the remaining data.
Will this break other snap packages that depend on this one?
Removing a snap package and its data should not break other packages, even if they depend on the one you are removing. The other packages would simply be unable to run until the dependency is reinstalled.
Do I need to restart snapd?
Restarting snapd is recommended to fully clear the removed package from snapd’s internal state. However, it is not strictly required in most cases.
What if I forget part of the removal process?
If you miss one of the removal steps, such as deleting the data directory, remnants of the old snap will be left behind. You can safely repeat the removal process to delete these. The steps are idempotent and will not cause issues if repeated.
Is there an easier way to do this?
Unfortunately there is no shortcut for removing a –purged snap package. You have to manually delete the data with the steps outlined above. It is more complex than a normal snap removal but necessary to fully purge the package.
Tutorial on Removing a Snap with Purge
Here is a simple tutorial for removing a snap package called “myapp” that was installed using the –purge flag:
-
Remove the snap package:
sudo snap remove myapp
-
Delete the snap data directory:
sudo rm -rf /var/snap/myapp/current
-
Check for common data:
ls /var/snap/common | grep myapp
If any output, delete the common data directories:
sudo rm -rf /var/snap/common/myapp*
-
Remove configuration:
sudo rm -rf /var/snap/myapp/*
-
Restart snapd:
sudo systemctl restart snapd
After following these steps, the myapp snap package and all its data will be fully removed from the system.
Example Purge Removal Process
Here is a detailed example showing the removal process for a snap package called “myapp” that was installed with the –purge flag:
# Original package installation sudo snap install myapp --purge # Package data saved to /var/snap/myapp/current # Now want to remove package completely # Step 1: Remove the snap package sudo snap remove myapp # Package removed but /var/snap/myapp/current still exists # Step 2: Delete data directory sudo rm -rf /var/snap/myapp/current # Step 3: Check for common data ls /var/snap/common | grep myapp # No output, so no common data to remove # Step 4: Remove configuration sudo rm -rf /var/snap/myapp # Step 5: Restart snapd sudo systemctl restart snapd # myapp snap package now fully removed
This demonstrates how to completely purge a snap package after installing with –purge by manually deleting the remaining data and restarting snapd.
Troubleshooting Purge Removal
Here are some tips for troubleshooting issues when trying to remove a purged snap package:
Snap remove fails
If snap remove fails, check whether the snap package is currently in use or running. You may need to stop the service before removing. Removing while the snap is running will fail.
Cannot delete data directory
Double check the data directory path under /var/snap/[package]. Make sure the current symlink exists before trying to delete. If not, the package may not have been installed properly.
Configuration files remain
Try using snap list --all
to check for any additional versions of the package configuration. Delete any other version directories under /var/snap/[package].
snapd will not restart
If systemctl restart snapd fails, check the systemd logs. You may need to purge and reinstall snapd itself to recover. This is rare but can happen if snapd’s state gets corrupted.
Summary
Removing a –purged snap package requires manually deleting the remaining data directory, configuration, and restarting snapd. Simply running snap remove will not work. Carefully follow the removal steps and troubleshooting tips outlined above to fully purge a complex snap package.
The main steps again are:
- snap remove
- rm -rf data directory
- rm configuration files
- restart snapd
Taking the extra time to properly purge a –purged snap package keeps your system clean and avoids leftover configuration or data causing issues down the line.
Video Guide
Here is a video walking through the key steps to remove a snap package installed with –purge:
Follow along with the video to see the purge removal process in action. Watch how the snap package data persists after snap remove and needs to be manually deleted.
Related Commands
Here are some other snap commands related to removal and purging:
snap remove
Basic command to remove an installed snap package. Will not remove data if –purge was used on install.
snap remove myapp
snap list
List installed snap packages. Use –all to show all revisions of a package.
snap list snap list --all
snap clean
Cleans up cached snap package files to recover disk space.
snap clean
Conclusion
Removing a snap package that was installed with –purge requires manually deleting the remaining package files and restarting snapd. Make sure to remove the package, data directory, configurations, and restart the service to fully purge it. Following the steps outlined in detail above will allow you to successfully remove all traces of a complex snap package.