APT Package Repository Management Guide
APT Package Repository Management Guide Introduction Understanding where your installed packages come from is crucial for system maintenance, security auditing, and troubleshooting. This guide shows how to identify package sources, manage repositories, list packages by origin, and audit your APT installation on Debian/Ubuntu systems. What are Package Repositories? Package repositories are servers that host software packages for installation via APT (Advanced Package Tool). Understanding repository sources helps you: Security: Identify packages from untrusted sources Maintenance: Track PPA dependencies Troubleshooting: Find conflicting package sources System Cleanup: Remove unused repositories Documentation: Maintain installation records Repository Types Type Description Example Official Ubuntu/Debian main repositories archive.ubuntu.com PPA Personal Package Archives (Ubuntu) ppa.launchpad.net/user/repo Third-party External repositories download.docker.com Local Locally installed packages /var/lib/dpkg/status Prerequisites Debian or Ubuntu-based system Basic terminal knowledge apt, dpkg, and perl installed (usually pre-installed) 馃殌 Quick Commands List All Packages with Repositories dpkg --get-selections | awk '!/deinstall$/ {print $1}' | \ xargs -I{} sh -c 'echo "=== $1 ===" && apt-cache policy "$1" | grep -E "^\s+\*\*\*" | head -1' -- {} | \ paste - - | sed 's/=== \([^ ]*\) ===/\1:/' | \ perl -pe 's/:\s+\*\*\*[^5]*500\s+/: /' | \ sed 's/\s\[.*\]$//' List Only PPA Packages dpkg --get-selections | awk '!/deinstall$/ {print $1}' | \ xargs -I{} apt-cache policy {} | \ perl -0777 -ne 'while(/^(\S+?):\n.*?\n\s+\*\*\*.*?500 http:\/\/ppa\.launchpad\.net\/([^\s\/]+)/gms) {print "$1: $2\n"}' Count Packages per Repository dpkg --get-selections | awk '!/deinstall$/ {print $1}' | \ xargs -I{} apt-cache policy {} 2>/dev/null | \ perl -0777 -ne 'while(/^(\S+?):\n.*?\n\s+\*\*\*.*?500\s+(http:\/\/[^\s]+)/gms) { $repo = $2; $repo =~ s/\s.*//; $repos{$repo}++ } END { for $r (sort keys %repos) { print "$r: $repos{$r} packages\n" } }' 馃摝 Complete Package Audit Script Full-featured bash script with multiple options Save as package-audit.sh: ...