# Linux Uninstallation & System Cleanup Guide

**A comprehensive guide to removing software installed via different methods**

*Created for Linux Mint 22.2 / Ubuntu-based systems*

---

## Table of Contents

1. [Quick Reference Table](#quick-reference-table)
2. [Method 1: APT/DPKG Packages](#method-1-aptdpkg-packages)
3. [Method 2: Flatpak Applications](#method-2-flatpak-applications)
4. [Method 3: Snap Packages](#method-3-snap-packages)
5. [Method 4: AppImages](#method-4-appimages)
6. [Method 5: Tarball Extracts (tar.gz/tar.xz)](#method-5-tarball-extracts)
7. [Method 6: Git Clones & Source Builds](#method-6-git-clones--source-builds)
8. [Method 7: Manual Installs & Third-Party Scripts](#method-7-manual-installs--third-party-scripts)
9. [Case Study: Removing Zen Browser](#case-study-removing-zen-browser)
10. [System Cleanup & Maintenance](#system-cleanup--maintenance)
11. [Nuclear Options](#nuclear-options)

---

## Quick Reference Table

| Installation Method | How to Identify | How to Remove | Difficulty |
|---------------------|-----------------|---------------|------------|
| **APT Package** | `dpkg -l \| grep name` | `sudo apt remove name` | ⭐ Easy |
| **Flatpak** | `flatpak list` | `flatpak uninstall name` | ⭐ Easy |
| **Snap** | `snap list` | `sudo snap remove name` | ⭐ Easy |
| **AppImage** | File in ~/Applications or ~/Downloads | Delete file + desktop entry | ⭐⭐ Medium |
| **Tarball Extract** | Usually in /opt or ~/local | Delete folder + desktop entry | ⭐⭐ Medium |
| **Source Build** | Check install logs or `make uninstall` | `sudo make uninstall` or manual | ⭐⭐⭐ Hard |
| **Script Install** | Check ~/.local or /opt | Follow uninstall script or manual | ⭐⭐⭐ Hard |

---

## Method 1: APT/DPKG Packages

**When you installed with:** `sudo apt install package-name`

### Check if installed
```bash
# Search for package
dpkg -l | grep package-name

# Get package info
apt show package-name

# List files installed by package
dpkg -L package-name
```

### Uninstall
```bash
# Remove package but keep config files
sudo apt remove package-name

# Remove package AND config files (recommended)
sudo apt purge package-name

# Remove with dependencies
sudo apt autoremove --purge package-name

# Clean up after removal
sudo apt autoremove
sudo apt autoclean
```

### Verify removal
```bash
dpkg -l | grep package-name
# Should return nothing
```

### Common locations to check
- Binaries: `/usr/bin/`, `/usr/local/bin/`
- Libraries: `/usr/lib/`, `/usr/local/lib/`
- Config: `/etc/package-name/`
- User data: `~/.config/package-name/`, `~/.local/share/package-name/`

---

## Method 2: Flatpak Applications

**When you installed with:** `flatpak install app-name`

### List all Flatpaks
```bash
flatpak list
```

### Uninstall
```bash
# Remove application
flatpak uninstall app.name.AppName

# Remove and delete user data
flatpak uninstall --delete-data app.name.AppName

# Remove unused runtimes/dependencies
flatpak uninstall --unused

# Full cleanup
flatpak repair
```

### Verify removal
```bash
flatpak list | grep app-name
```

### Manual data cleanup
```bash
# User data location
rm -rf ~/.var/app/app.name.AppName/

# Check Flatpak cache
du -sh ~/.local/share/flatpak/
```

**Pro tip:** Flatpak apps store data in `~/.var/app/` - each app gets its own sandbox folder.

---

## Method 3: Snap Packages

**When you installed with:** `sudo snap install package-name`

### List all Snaps
```bash
snap list
```

### Uninstall
```bash
# Remove snap
sudo snap remove package-name

# Remove snap and all revisions
sudo snap remove --purge package-name

# Disable snapd entirely (if you hate Snap)
sudo systemctl disable snapd.service
sudo systemctl disable snapd.socket
sudo apt purge snapd
```

### Verify removal
```bash
snap list | grep package-name
```

### Manual cleanup
```bash
# Snap data locations
rm -rf ~/snap/package-name/

# System snap folder
sudo rm -rf /var/snap/package-name/
```

**Note:** Snaps auto-update and keep old revisions. Always use `--purge` to fully clean up.

---

## Method 4: AppImages

**When you downloaded:** `Application-x86_64.AppImage`

### Characteristics
- Single executable file
- Usually in `~/Downloads/`, `~/Applications/`, or `~/.local/bin/`
- May have created desktop entry
- May have created config in `~/.config/`

### Uninstall process

#### Step 1: Find the AppImage
```bash
# Search common locations
find ~ -name "*.AppImage" 2>/dev/null

# List recently modified AppImages
find ~ -name "*.AppImage" -mtime -30 2>/dev/null
```

#### Step 2: Remove the file
```bash
rm ~/path/to/Application.AppImage
```

#### Step 3: Remove desktop entry
```bash
# Check for desktop file
ls ~/.local/share/applications/ | grep -i application

# Remove it
rm ~/.local/share/applications/application-name.desktop
```

#### Step 4: Remove config/data
```bash
# Check common locations
ls ~/.config/ | grep -i application
ls ~/.local/share/ | grep -i application

# Remove folders
rm -rf ~/.config/application-name/
rm -rf ~/.local/share/application-name/
```

#### Step 5: Update desktop database
```bash
update-desktop-database ~/.local/share/applications/
```

### Example: Removing Logseq AppImage
```bash
# 1. Find and remove AppImage
rm ~/Downloads/Logseq-linux-x64-*.AppImage

# 2. Remove desktop entry
rm ~/.local/share/applications/logseq.desktop

# 3. Remove data
rm -rf ~/.config/Logseq/
rm -rf ~/.local/share/Logseq/

# 4. Update database
update-desktop-database ~/.local/share/applications/
```

---

## Method 5: Tarball Extracts

**When you extracted:** `tar -xzf package.tar.gz` and moved to `/opt/` or `~/local/`

### Common install locations
- `/opt/package-name/`
- `~/.local/package-name/`
- `/usr/local/package-name/`

### Uninstall process

#### Step 1: Find installation directory
```bash
# Check /opt
ls /opt/ | grep -i package

# Check ~/.local
ls ~/.local/ | grep -i package

# Find executable location
which package-name
```

#### Step 2: Remove directory
```bash
# If in /opt (requires sudo)
sudo rm -rf /opt/package-name/

# If in ~/.local
rm -rf ~/.local/package-name/
```

#### Step 3: Remove symlinks/shortcuts
```bash
# Check for symlinks in PATH
ls -la /usr/local/bin/ | grep package-name
sudo rm /usr/local/bin/package-name

# Or in ~/.local/bin
ls -la ~/.local/bin/ | grep package-name
rm ~/.local/bin/package-name
```

#### Step 4: Remove desktop entry
```bash
# System-wide
sudo rm /usr/share/applications/package-name.desktop

# User-specific
rm ~/.local/share/applications/package-name.desktop
```

#### Step 5: Clean up config
```bash
rm -rf ~/.config/package-name/
rm -rf ~/.local/share/package-name/
```

### Example: Removing VSCodium tarball
```bash
# 1. Remove installation
sudo rm -rf /opt/vscodium/

# 2. Remove symlink
sudo rm /usr/local/bin/codium

# 3. Remove desktop entry
sudo rm /usr/share/applications/codium.desktop

# 4. Remove user config
rm -rf ~/.config/VSCodium/
```

---

## Method 6: Git Clones & Source Builds

**When you did:**
```bash
git clone https://github.com/user/repo
cd repo
make
sudo make install
```

### The Challenge
Source builds scatter files across system directories. No package manager tracks them.

### Uninstall strategies

#### Strategy 1: Use `make uninstall` (if available)
```bash
cd /path/to/source/directory
sudo make uninstall
```

**Problem:** Not all projects include `uninstall` target.

#### Strategy 2: Check install logs
```bash
# Run install again, save output
sudo make install > install.log 2>&1

# Review what was installed
cat install.log

# Remove files manually based on log
```

#### Strategy 3: Use `checkinstall` (retroactive tracking)

**For future installs, use checkinstall instead of `make install`:**
```bash
sudo apt install checkinstall

# Instead of: sudo make install
sudo checkinstall

# This creates a .deb package you can uninstall later
sudo dpkg -r package-name
```

#### Strategy 4: Manual removal (last resort)

**Common install locations for source builds:**
```bash
# Binaries
/usr/local/bin/
/usr/bin/

# Libraries
/usr/local/lib/
/usr/lib/

# Headers
/usr/local/include/
/usr/include/

# Man pages
/usr/local/share/man/
/usr/share/man/

# Data files
/usr/local/share/package-name/
/usr/share/package-name/
```

**Removal process:**
```bash
# 1. Find binary
which program-name
sudo rm $(which program-name)

# 2. Search for related files
find /usr/local -name "*program*" 2>/dev/null
find /usr -name "*program*" 2>/dev/null

# 3. Remove carefully
sudo rm -rf /usr/local/lib/program-name/
sudo rm -rf /usr/local/share/program-name/
```

### Example: Removing a Git clone + build

```bash
# Example: Removing a program built from source

# 1. Try make uninstall first
cd ~/repos/program-name/
sudo make uninstall

# 2. If that fails, find files manually
sudo find /usr/local -name "*program*" -ls

# 3. Remove them
sudo rm /usr/local/bin/program-name
sudo rm -rf /usr/local/share/program-name/

# 4. Remove git clone
rm -rf ~/repos/program-name/

# 5. Update man pages database
sudo mandb

# 6. Update shared library cache
sudo ldconfig
```

---

## Method 7: Manual Installs & Third-Party Scripts

**When you ran:** `curl -sSL https://install.script | bash`

### The Nuclear Problem
Install scripts can put files **anywhere**. You need to be a detective.

### Investigation process

#### Step 1: Check what the script does
```bash
# Re-download and READ the script (don't run)
curl -sSL https://install.script > script.sh
cat script.sh | less

# Look for:
# - Where files are copied
# - What directories are created
# - Symlinks created
# - Services installed
```

#### Step 2: Check common locations

**User-specific:**
```bash
~/.local/bin/
~/.local/share/
~/.config/
```

**System-wide:**
```bash
/opt/
/usr/local/bin/
/usr/local/lib/
/usr/local/share/
/etc/
```

**Services:**
```bash
/etc/systemd/system/
~/.config/systemd/user/
```

#### Step 3: Check running processes
```bash
# See what's running
ps aux | grep program-name

# Check systemd services
systemctl list-units --type=service | grep program-name
systemctl --user list-units --type=service | grep program-name
```

#### Step 4: Removal checklist

```bash
# Stop services
sudo systemctl stop program-name.service
sudo systemctl disable program-name.service
systemctl --user stop program-name.service

# Remove service files
sudo rm /etc/systemd/system/program-name.service
rm ~/.config/systemd/user/program-name.service

# Reload systemd
sudo systemctl daemon-reload

# Remove binaries
sudo rm /usr/local/bin/program-name

# Remove data
sudo rm -rf /opt/program-name/
rm -rf ~/.local/share/program-name/
rm -rf ~/.config/program-name/

# Remove logs
sudo rm -rf /var/log/program-name/
```

### Example: Removing PyEnv (curl installer)

```bash
# PyEnv installs to ~/.pyenv

# 1. Remove installation
rm -rf ~/.pyenv/

# 2. Remove from shell config
nano ~/.bashrc
# Delete these lines:
# export PYENV_ROOT="$HOME/.pyenv"
# export PATH="$PYENV_ROOT/bin:$PATH"
# eval "$(pyenv init -)"

# 3. Reload shell
source ~/.bashrc

# 4. Verify
which pyenv
# Should return nothing
```

---

## Case Study: Removing Zen Browser

**Zen Browser can be installed via Flatpak OR tarball - you need to identify which.**

### Step 1: Identify installation method

```bash
# Check if Flatpak
flatpak list | grep -i zen

# Check if tarball (common locations)
ls /opt/ | grep -i zen
ls ~/.local/ | grep -i zen

# Check running process
ps aux | grep zen

# Find executable
which zen-browser
```

### Step 2A: If Flatpak

```bash
# Get exact app ID
flatpak list | grep -i zen

# Uninstall
flatpak uninstall io.github.zen-browser.zen

# Remove data
rm -rf ~/.var/app/io.github.zen-browser.zen/

# Clean up
flatpak uninstall --unused
```

### Step 2B: If Tarball

```bash
# Find installation directory
find ~ /opt -name "*zen*" -type d 2>/dev/null

# Example locations:
# /opt/zen-browser/
# ~/.local/zen-browser/

# Remove installation
sudo rm -rf /opt/zen-browser/
# OR
rm -rf ~/.local/zen-browser/

# Remove symlinks
sudo rm /usr/local/bin/zen-browser
rm ~/.local/bin/zen-browser

# Remove desktop entry
rm ~/.local/share/applications/zen-browser.desktop
sudo rm /usr/share/applications/zen-browser.desktop

# Remove config/data
rm -rf ~/.zen/
rm -rf ~/.config/zen/
rm -rf ~/.local/share/zen/
rm -rf ~/.cache/zen/

# Update desktop database
update-desktop-database ~/.local/share/applications/
```

### Step 3: Remove Zen-specific artifacts

```bash
# Remove MIME associations
xdg-mime query default x-scheme-handler/http
# If it shows zen, change it:
xdg-mime default microsoft-edge.desktop x-scheme-handler/http
xdg-mime default microsoft-edge.desktop x-scheme-handler/https

# Remove from mimeapps.list
nano ~/.config/mimeapps.list
# Delete any lines with "Zen" in them

# Clear recent files that might reference Zen
rm ~/.local/share/recently-used.xbel
```

### Step 4: Verify complete removal

```bash
# Check for any remaining files
find ~ -iname "*zen*" 2>/dev/null | grep -v ".cache"

# Check for running processes
ps aux | grep zen

# Check default browser
xdg-settings get default-web-browser

# Test opening a link
xdg-open https://google.com
```

---

## System Cleanup & Maintenance

### After uninstalling multiple apps

#### Clean package manager caches
```bash
# APT cleanup
sudo apt autoremove
sudo apt autoclean
sudo apt clean

# Flatpak cleanup
flatpak uninstall --unused
flatpak repair

# Snap cleanup (removes old revisions)
sudo snap list --all | awk '/disabled/{print $1, $3}' | while read snapname revision; do
    sudo snap remove "$snapname" --revision="$revision"
done
```

#### Find and remove orphaned config files
```bash
# List config directories
ls ~/.config/

# Remove configs for uninstalled apps
rm -rf ~/.config/app-that-no-longer-exists/
```

#### Clean thumbnail cache
```bash
# Can grow to several GB
rm -rf ~/.cache/thumbnails/*
```

#### Clean old logs
```bash
# User logs
rm -rf ~/.local/share/xorg/*.log.old

# System logs (careful!)
sudo journalctl --vacuum-time=7d
```

#### Find large files/directories
```bash
# Top 20 largest directories in home
du -h ~ | sort -rh | head -20

# Find files larger than 100MB
find ~ -type f -size +100M -exec ls -lh {} \; 2>/dev/null
```

#### Clean browser caches
```bash
# Firefox
rm -rf ~/.cache/mozilla/

# Chromium-based
rm -rf ~/.cache/chromium/
rm -rf ~/.cache/microsoft-edge/
```

#### Remove old kernels (frees 200-500MB per kernel)
```bash
# List installed kernels
dpkg -l | grep linux-image

# Keep current + one previous, remove rest
sudo apt autoremove --purge
```

#### Clean Docker (if installed)
```bash
# Remove unused containers, images, volumes
docker system prune -a --volumes

# See space usage
docker system df
```

---

## Nuclear Options

**When you want to start fresh with something**

### Reset application to defaults

```bash
# Remove all config/data for an app
rm -rf ~/.config/application-name/
rm -rf ~/.local/share/application-name/
rm -rf ~/.cache/application-name/

# Reinstall will create fresh config
```

### Clean entire user home directory

```bash
# Backup first!
tar -czf ~/backup-$(date +%Y%m%d).tar.gz ~/.config ~/.local

# Remove all app configs (DANGEROUS)
rm -rf ~/.config/*
rm -rf ~/.local/share/*
rm -rf ~/.cache/*

# Keep these critical configs:
# - ~/.bashrc, ~/.profile
# - ~/.ssh/
# - ~/.gnupg/
```

### System-wide cleanup

```bash
# WARNING: This will break things if you don't know what you're doing

# Remove all orphaned packages
sudo apt autoremove --purge

# Remove all cached packages
sudo apt clean

# Remove all snap packages
for snap in $(snap list | awk 'NR>1 {print $1}'); do
    sudo snap remove --purge "$snap"
done

# Remove snapd entirely
sudo apt purge snapd
```

---

## Best Practices

### Before installing anything

1. **Document what you install:**
   ```bash
   # Create an install log
   echo "$(date): Installed program-name via method" >> ~/install-log.txt
   ```

2. **Take a Timeshift snapshot** before major installations

3. **Prefer package managers over manual installs:**
   - APT > Flatpak > AppImage > Tarball > Source build

4. **Use `checkinstall` for source builds:**
   ```bash
   sudo checkinstall
   # Creates .deb you can track and remove
   ```

### When uninstalling

1. **Stop services first:**
   ```bash
   sudo systemctl stop service-name
   sudo systemctl disable service-name
   ```

2. **Remove in reverse order of installation:**
   - User data first
   - Then binaries
   - Then libraries
   - Finally config files

3. **Use `--purge` whenever possible:**
   ```bash
   sudo apt purge package-name  # Not just 'remove'
   ```

4. **Clean up after yourself:**
   ```bash
   sudo apt autoremove
   flatpak uninstall --unused
   update-desktop-database ~/.local/share/applications/
   ```

### Regular maintenance schedule

**Weekly:**
- `sudo apt autoremove`
- `flatpak uninstall --unused`

**Monthly:**
- Review `~/.config/` for orphaned folders
- Clear `~/.cache/thumbnails/`
- Run `docker system prune` (if using Docker)

**Quarterly:**
- Take inventory of installed software
- Remove unused applications
- Take fresh Timeshift snapshot
- Review startup services

---

## Troubleshooting

### "Package not found" when trying to remove
```bash
# Check what method was used
dpkg -l | grep package-name
flatpak list | grep package-name
snap list | grep package-name

# Find files manually
sudo find / -name "*package*" 2>/dev/null
```

### Desktop entry won't disappear
```bash
# Update database
update-desktop-database ~/.local/share/applications/

# Check both locations
ls ~/.local/share/applications/ | grep package
ls /usr/share/applications/ | grep package
```

### "Directory not empty" errors
```bash
# See what's left
ls -la /path/to/directory/

# Force remove if safe
sudo rm -rf /path/to/directory/
```

### Application still appears in menu after removal
```bash
# Clear menu cache
rm ~/.cache/menus/*

# Restart panel
xfce4-panel -r

# Or log out and back in
```

---

## Summary

**Golden Rule:** Before installing anything, ask yourself:
1. How will I uninstall this?
2. Where will files be placed?
3. Is there a package manager version?

**Priority order for installations:**
1. APT package (easiest to remove)
2. Flatpak (sandboxed, clean removal)
3. AppImage (single file, portable)
4. Tarball extract (manual but contained)
5. Source build (hardest to track)

**When in doubt:**
- Check `dpkg -l`, `flatpak list`, `snap list`
- Use `find / -name "*program*"` to locate files
- Document your installs
- Take Timeshift snapshots

**Remember:** Modern Linux is designed to be messy-proof. Most installations can't break your system permanently. The worst case is a few leftover files taking up disk space.

---

**Created:** October 2025  
**For:** Linux Mint 22.2 (Zara) / Ubuntu 24.04 base  
**License:** Do whatever you want with this guide

---

## Additional Resources

- [Arch Wiki - Pacman/Remove](https://wiki.archlinux.org/title/Pacman/Removing_packages) (concepts apply to all distros)
- [Debian Wiki - Uninstalling](https://wiki.debian.org/Uninstalling)
- [Flatpak Documentation](https://docs.flatpak.org/en/latest/using-flatpak.html)
- [AppImageHub](https://appimage.github.io/) - Check for official uninstall instructions

Need help? Check `/var/log/dpkg.log` to see what was installed and when.
