Last active
July 19, 2026 21:14
-
-
Save timsonner/11726fec5a0534a8881a4dbbbc6985b1 to your computer and use it in GitHub Desktop.
Debloat Ubuntu 26.04: Remove Snaps (App Store), MOTD, Software Updater, Help, and Ubuntu Pro / ESM messages in apt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # --- 1. Disable MOTD News --- | |
| systemctl stop motd-news.timer motd-news.service | |
| systemctl disable motd-news.timer | |
| chmod -x /etc/update-motd.d/50-motd-news | |
| if [ -f /etc/default/motd-news ]; then | |
| sed -i 's/^ENABLED=1/ENABLED=0/' /etc/default/motd-news | |
| fi | |
| # --- 2. Clean Up Snapd --- | |
| # Unmount active snap mounts if any remain | |
| if grep -q '/snap/' /proc/mounts; then | |
| for m in $(grep '/snap/' /proc/mounts | awk '{print $2}'); do | |
| umount -l "$m" | |
| done | |
| fi | |
| if [ -d /snap ]; then | |
| umount /snap | |
| fi | |
| if [ -d /var/snap ]; then | |
| umount /var/snap | |
| fi | |
| # Stop services if they exist | |
| systemctl stop snapd.socket snapd.service snapd.seeded.service | |
| systemctl disable snapd.socket snapd.service snapd.seeded.service | |
| # Purge snapd package if currently installed | |
| if dpkg -l | grep -q "^ii snapd "; then | |
| apt purge -y --autoremove snapd | |
| fi | |
| # Pin snapd so APT ignores it completely | |
| cat <<'EOF' > /etc/apt/preferences.d/no-snapd.pref | |
| Package: snapd | |
| Pin: release * | |
| Pin-Priority: -1 | |
| EOF | |
| # Clean leftover Snap directories | |
| rm -rf /snap ~/snap /var/snap /var/cache/snapd /var/lib/snapd | |
| # --- 3. Remove Software & Update Managers --- | |
| # Check which target packages are installed first so APT doesn't throw 'not installed' warnings | |
| PKGS_TO_REMOVE=() | |
| for pkg in update-manager update-notifier unattended-upgrades yelp ubuntu-docs gnome-user-docs; do | |
| if dpkg -l | grep -q "^ii $pkg "; then | |
| PKGS_TO_REMOVE+=("$pkg") | |
| fi | |
| done | |
| if [ ${#PKGS_TO_REMOVE[@]} -gt 0 ]; then | |
| apt purge -y --autoremove "${PKGS_TO_REMOVE[@]}" | |
| fi | |
| # --- 4. Completely Neutralize Ubuntu Pro / ESM in APT --- | |
| # Disable APT news | |
| pro config set apt_news=false | |
| # Clean up any leftover file from previous dpkg-divert run | |
| if [ -f /etc/apt/apt.conf.d/20apt-esm-hook.conf.distrib ]; then | |
| rm -f /etc/apt/apt.conf.d/20apt-esm-hook.conf.distrib | |
| fi | |
| # Disable ESM hook by moving the file (avoids APT invalid extension warnings) | |
| if [ -f /etc/apt/apt.conf.d/20apt-esm-hook.conf ]; then | |
| mv /etc/apt/apt.conf.d/20apt-esm-hook.conf /etc/apt/apt.conf.d/20apt-esm-hook.conf.disabled | |
| fi | |
| # Mask background ESM and APT news generation services | |
| systemctl mask apt-news.service esm-cache.service | |
| # --- 5. Reload Systemd Daemon & Final Cleanup --- | |
| systemctl daemon-reload | |
| apt autoremove -y --purge |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment