This is my Ubuntu package management cheat sheet (including apt/apt-get/apt-cache/APT preferences files).
1. Location of APT cache# repository metadata2. Source List file
/var/lib/apt/lists/
# a cache of already downloaded packages to avoid downloading them again
/var/cache/apt/archives
# Downloading-in-progress packages
/var/cache/apt/archives/partial
/etc/apt/sources.list3. Clean /var/cache/apt/archives except lock file and partial folder
apt-get clean4. Clean /var/cache/apt/archives for packages which can no longer be downloaded
apt-get autoclean5. Downloads the package lists from the repositories
# Clean /var/cache/apt/archives for packages that were installed automatically to satisfy the dependencies of another installed package.
# If that package is removed, below commands can remove those automatically installed packages.
apt autoremove
apt-get autoclean
apt-get update6. List upgradable or installed packages
apt update
apt list --upgradable7. Search for a package in the local APT cache
apt list --installed
apt list --all-versions
apt-cache search package_name8. Get detailed metadata information of a package
apt-cache search --names-only package_name
apt-cache search --names-only --full package_name
apt search package_name
apt search --names-only package_name
apt search --names-only --full package_name
apt-cache show package_name9. Show Package name, Versions and Dependencies
apt show package_name
apt-cache showpkg package_name10. Show whether package is installed, which version is available which which repository and priority
apt-cache policy package_name
apt policy package_name
Note: Default priority for installed package : 100, for non-installed package: 500.
11. Check dependenciesapt-cache depends package_name12. Check reverse dependencies
apt depends package_name
apt-cache rdepends package_name13. Check all unmet dependencies of available packages
apt rdepends package_name
apt-cache unmet14. List all available packages
apt-cache pkgnames | wc -l15. Upgrade installed packages
apt-get upgrade
apt upgrade
# Only stable distribution
apt -t stable upgrade
# full-upgrade may remove a installed obsolete package or install new dependencies if needed.
apt full-upgrade
16. Install a package
apt-get install package_name
apt install package_name
17. Install a package without upgrade
apt-get install package_name --no-upgrade
apt install package_name --no-upgrade
18. Only upgrade without installing it
apt-get install package_name --only-upgrade
apt install package_name --only-upgrade
19. Install specific version of package
apt-get install package_name=version_number20. Remove a package but leave configuration files
apt install package_name=version_number
apt-get remove package_name21. Remove a package including configuration files
apt remove package_name
apt-get purge package_name
apt purge package_name
22. Retrieve all installed packages into a file
dpkg --get-selections > pkg-list
23. Dump all available packages
apt-cache dumpavail
24. Install and Remove packages at the same time
apt install package1 package2-
apt remove package1+ package2
25. Reinstall a package if it is damaged
apt --reinstall install package_name
26. Install a specific distribution of package
apt install package_name/unstable
apt install package_name/experimental
27. Install a .deb
apt install ./package_name
28. Package priority
APT checks /etc/apt/preferences and /etc/apt/preferences.d/ by folllowing below rules:
< 0
will never be installed,
1..99
will only be installed if no other version of the package is already installed,
100..499
will only be installed if there is no other newer version installed or available in another distribution,
500....989
will only be installed if there is no newer version installed or available in the target distribution,
990..1000
will be installed except if the installed version is newer,
> 1000
will always be installed, even if it forces APT to downgrade to an older version.
29. Distribution
Stable, Testing, Unstable or Experimental...
30. Sample APT preferences files
# Allow installing experimental packages
Package: *
Pin: release a=experimental
Pin-Priority: 500
# Only install Stable packages of Debian
Package: *
Pin: release a=stable
Pin-Priority: 900
Package: *
Pin: release o=Debian
Pin-Priority: -10
# Keep Perl 5.24
Package: perl
Pin: version 5.24*
Pin-Priority: 1001
# High priority for local packages
Package: *
Pin: origin ""
Pin-Priority: 999
# High priority for Codename is "buster"
Package: *
Pin: release n=buster
Pin-Priority: 900
31. APT preference manual
man apt_preferences
32. Comments in /etc/apt/preferences
Explanation: xxx
33. why an automatically installed package is present on the system
aptitude why package_name
34. List installed packages that no other package depends on
deborphan
References:
https://debian-handbook.info/browse/stable/sect.apt-get.html#sect.apt.priorities
https://www.howtoforge.com/a-short-introduction-to-apt-pinning-p2
No comments:
Post a Comment