/check-apt-health
You are helping the user ensure that the APT package manager on Ubuntu is in good working health and remove any broken third-party repositories or packages.
From linux-desktop-mgmtnpx claudepluginhub danielrosehill/claude-code-plugins --plugin lan-managerAPT Package Manager Health Check
You are helping the user ensure that the APT package manager on Ubuntu is in good working health and remove any broken third-party repositories or packages.
Your tasks:
-
Check basic APT functionality:
- Update package lists:
sudo apt update - Check for errors in output
- Verify cache state:
apt-cache policy
- Update package lists:
-
Check for broken packages:
- List broken packages:
dpkg -l | grep "^..r" - Check for unconfigured packages:
dpkg -l | grep "^..c" - Check dpkg status:
sudo dpkg --configure -a - Check for broken dependencies:
sudo apt-get check
- List broken packages:
-
Identify problematic repositories:
- List all repositories:
grep -r --include '*.list' '^deb ' /etc/apt/sources.list /etc/apt/sources.list.d/ - Check for failing repositories during update:
sudo apt update 2>&1 | grep -i "fail\|error\|warning" - List third-party PPAs:
ls /etc/apt/sources.list.d/
- List all repositories:
-
Check APT cache integrity:
- Check cache size:
du -sh /var/cache/apt/archives/ - List problematic cache entries:
sudo apt-get clean sudo apt-get autoclean
- Check cache size:
-
Fix broken dependencies:
- Attempt to fix broken packages:
sudo apt --fix-broken install - Force reconfiguration of all packages:
sudo dpkg --configure -a - Try to complete interrupted installations:
sudo apt-get -f install
- Attempt to fix broken packages:
-
Identify and handle broken third-party repositories: For each failing repository found:
- Ask user if they still need it
- If not needed, disable or remove:
sudo add-apt-repository --remove ppa:<ppa-name> - Or manually remove:
sudo rm /etc/apt/sources.list.d/<repo>.list - Or disable by commenting out:
sudo sed -i 's/^deb/#deb/' /etc/apt/sources.list.d/<repo>.list
-
Check for GPG key issues:
- Check for missing GPG keys:
sudo apt update 2>&1 | grep "NO_PUBKEY" - If missing keys found, attempt to import:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <KEY> - List all trusted keys:
apt-key list
- Check for missing GPG keys:
-
Check for duplicate repositories:
- Find duplicates:
grep -h "^deb " /etc/apt/sources.list /etc/apt/sources.list.d/* | sort | uniq -d - Remove duplicates manually or ask user which to keep
- Find duplicates:
-
Check disk space:
- Disk space in /var:
df -h /var - If low on space:
sudo apt-get clean sudo apt-get autoclean sudo apt-get autoremove
- Disk space in /var:
-
Check for held packages:
- List held packages:
apt-mark showhold - These packages won't be upgraded - ask user if intentional
- To unhold:
sudo apt-mark unhold <package-name>
- List held packages:
-
Verify repository configurations:
- Check main sources.list:
cat /etc/apt/sources.list - Ensure official Ubuntu repositories are present:
- main
- restricted
- universe
- multiverse
- security updates
- updates
- backports (optional)
- Check main sources.list:
-
Check for obsolete packages:
- List locally installed packages not in any repository:
aptitude search '~o' - Or using apt:
apt list '~o'
- List locally installed packages not in any repository:
-
Verify package authentication:
- Check if packages are being verified:
grep -r "APT::Get::AllowUnauthenticated" /etc/apt/ - Should be "false" or not present for security
- Check if packages are being verified:
-
Run full system check:
- Check for consistency:
sudo apt-get check - Simulate upgrade to check for issues:
sudo apt-get -s upgrade - Simulate dist-upgrade:
sudo apt-get -s dist-upgrade
- Check for consistency:
-
Clean up:
- Remove old packages:
sudo apt-get autoremove - Clean package cache:
sudo apt-get clean - Clean old cached packages:
sudo apt-get autoclean
- Remove old packages:
-
Reset APT if severely broken: If APT is severely corrupted, may need to:
# Backup current sources sudo cp -r /etc/apt /etc/apt.backup # Reset dpkg sudo dpkg --clear-avail sudo apt-get update # Reinstall base packages if needed sudo apt-get install --reinstall apt dpkg -
Check APT configuration files:
- List all APT config:
apt-config dump - Check for problematic configurations in:
/etc/apt/apt.conf/etc/apt/apt.conf.d/
- Look for unusual proxy settings, deprecated options
- List all APT config:
-
Report findings: Summarize:
- Number of broken packages (if any)
- Problematic repositories (outdated PPAs, failing repos)
- Missing GPG keys
- Dependency issues
- Disk space issues
- Held packages
- Overall APT health status (HEALTHY / NEEDS ATTENTION / BROKEN)
-
Provide recommendations:
- List of repositories to remove
- Packages to fix or remove
- Whether full system upgrade is recommended
- Cleanup commands to run
- Any configuration changes needed
- If APT is healthy, suggest regular maintenance:
sudo apt update && sudo apt upgrade sudo apt autoremove sudo apt clean
Important notes:
- Always backup before removing repositories or packages
- Don't remove dependencies of packages user needs
- Some third-party repos may be intentionally added - confirm before removing
- Be cautious with --fix-broken - it may remove packages
- Check if user is running unsupported Ubuntu version (EOL)
- PPAs may lag behind Ubuntu releases
- sudo is required for most operations
- After major fixes, suggest reboot to ensure clean state