I'm sorry to hear you're experiencing issues with Snap on your Ubuntu system. Snap packages can sometimes consume significant disk space and may install applications in locations that are inconvenient for some users. Below are several steps and strategies you can use to manage Snap packages more effectively, reduce disk space usage, or even remove Snap entirely if you prefer.
1. Understand Snap's Structure and Disk Usage
Snap packages bundle all their dependencies, which can lead to larger disk usage compared to traditional apt packages. Snap stores its data in /var/lib/snapd and maintains user-specific data in the $HOME/snap directory.
To check the disk usage of Snap:
sudo du -h /var/lib/snapd
du -h ~/snap
2. Remove Unnecessary Snap Packages
First, list all installed Snap packages:
snap list
Identify the snaps you no longer need and remove them:
sudo snap remove <snap-name>
Replace <snap-name> with the name of the Snap package you wish to remove.
3. Clean Up Old Snap Revisions
Snap keeps previous revisions of packages, which can accumulate over time. To remove old revisions and free up space:
a. Install the unsnap tool:
sudo snap install unsnap
b. Run unsnap to remove old revisions:
unsnap
Alternatively, you can manually remove old revisions by keeping only the current and one previous version:
snap list --all | awk '/disabled/{print $1, $2, $3}' | while read snapname revision channel; do
sudo snap remove "$snapname" --revision="$revision"
done
4. Move Snap’s Mount Point
By default, Snap mounts its filesystem in /var/lib/snapd/snaps. If you're constrained by space in your root partition, you can move this to another partition:
WARNING: This process is advanced and can cause system instability if not done correctly. Proceed with caution and consider backing up important data.
a. Stop the Snap service:
sudo systemctl stop snapd
b. Move the Snap directory:
sudo mv /var/lib/snapd /path/to/new/location/snapd
c. Create a symbolic link:
sudo ln -s /path/to/new/location/snapd /var/lib/snapd
d. Restart the Snap service:
sudo systemctl start snapd
Ensure that /path/to/new/location is a mounted partition with sufficient space.
5. Prevent Applications from Using Snap Instead of apt
Some applications available via both Snap and apt. To install them using apt instead of Snap:
a. Remove the Snap version of the application:
sudo snap remove <snap-name>
b. Install the application via apt:
sudo apt update
sudo apt install <package-name>
Note: Not all applications have direct equivalents in apt, and some newer versions might only be available via Snap.
6. Disable or Remove Snap Completely
If you prefer not to use Snap at all, you can remove it. However, be aware that some Ubuntu applications depend on Snap, and removing it might affect system functionality.
a. Remove Snap Packages and Snapd
# Remove all installed snaps
snap list | awk '{print $1}' | grep -v "Name" | xargs sudo snap remove
# Purge snapd
sudo apt purge snapd
# Remove any remaining snap directories
sudo rm -rf ~/snap
sudo rm -rf /var/snap
sudo rm -rf /var/lib/snapd
sudo rm -rf /var/cache/snapd
sudo rm -rf /snap
b. Prevent Snap from Reinstalling
To prevent Snap from being reinstalled during system updates, you can mask the Snapd service:
sudo systemctl mask snapd.service
sudo systemctl mask snapd.socket
sudo systemctl mask snapd.seeded.service
c. Install Alternative Software Sources
Ensure that you have alternative repositories and sources to install applications you need via apt, Flatpak, or other package managers.
7. Consider Using Flatpak as an Alternative
If you still want the benefits of containerized applications without using Snap, you might consider using Flatpak:
a. Install Flatpak
sudo apt install flatpak
b. Add the Flathub repository
sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
c. Install Applications via Flatpak
Browse available applications on Flathub and install them using Flatpak. For example:
flatpak install flathub org.mozilla.firefox
8. Regular Maintenance
Regularly check and clean up unnecessary Snap packages and revisions to keep disk usage in check. Automate the cleanup process using cron jobs or systemd timers if necessary.
Summary
Snap packages offer advantages like dependency management and sandboxing but can sometimes lead to increased disk usage and less flexibility in where data is stored. By carefully managing Snap packages, removing unnecessary ones, cleaning up old revisions, or even replacing Snap with alternative package managers like apt or Flatpak, you can optimize your Ubuntu system to better suit your storage and usage preferences.
If you decide to remove Snap entirely, ensure that you have alternative ways to install the software you need to maintain system functionality.
Feel free to ask if you need more detailed instructions on any of the steps above or have other questions!