This is my Ubuntu package management cheat sheet (including apt/apt-get/apt-cache/APT preferences files).
1. Location of APT cache1 2 3 4 5 6 7 8 | # repository metadata /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 |
1 | /etc/apt/sources .list |
1 | apt-get clean |
1 2 3 4 5 6 | apt-get autoclean # 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 |
1 2 | apt-get update apt update |
1 2 3 | apt list --upgradable apt list --installed apt list --all-versions |
1 2 3 4 5 6 7 | apt-cache search package_name 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 |
1 2 | apt-cache show package_name apt show package_name |
1 | apt-cache showpkg package_name |
1 2 | apt-cache policy package_name apt policy package_name |
Note: Default priority for installed package : 100, for non-installed package: 500.
11. Check dependencies1 2 | apt-cache depends package_name apt depends package_name |
1 2 | apt-cache rdepends package_name apt rdepends package_name |
1 | apt-cache unmet |
1 | apt-cache pkgnames | wc -l |
1 2 3 4 5 6 7 8 | 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
1 2 | apt-get install package_name apt install package_name |
17. Install a package without upgrade
1 2 | apt-get install package_name --no-upgrade apt install package_name --no-upgrade |
18. Only upgrade without installing it
1 2 | apt-get install package_name --only-upgrade apt install package_name --only-upgrade |
19. Install specific version of package
1 2 | apt-get install package_name=version_number apt install package_name=version_number |
1 2 | apt-get remove package_name apt remove package_name |
1 2 | apt-get purge package_name apt purge package_name |
22. Retrieve all installed packages into a file
1 | dpkg --get-selections > pkg-list |
23. Dump all available packages
1 | apt-cache dumpavail |
24. Install and Remove packages at the same time
1 2 | apt install package1 package2- apt remove package1+ package2 |
25. Reinstall a package if it is damaged
1 | apt --reinstall install package_name |
26. Install a specific distribution of package
1 2 | apt install package_name /unstable apt install package_name /experimental |
27. Install a .deb
1 | apt install . /package_name |
28. Package priority
APT checks /etc/apt/preferences and /etc/apt/preferences.d/ by folllowing below rules:
1 2 3 4 5 6 7 8 9 10 11 12 | < 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | # 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
1 | man apt_preferences |
32. Comments in /etc/apt/preferences
1 | Explanation: xxx |
33. why an automatically installed package is present on the system
1 | aptitude why package_name |
34. List installed packages that no other package depends on
1 | 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