0% found this document useful (0 votes)
8 views7 pages

APT Commands CheatSheet

This document is a comprehensive cheat sheet for APT commands, covering installation, removal, updating, searching, and managing packages in a Linux environment. It includes commands for handling dependencies, repositories, and configurations, as well as utilities for debugging and logging. The cheat sheet serves as a quick reference for users to efficiently manage software packages using APT.

Uploaded by

mysteryrn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views7 pages

APT Commands CheatSheet

This document is a comprehensive cheat sheet for APT commands, covering installation, removal, updating, searching, and managing packages in a Linux environment. It includes commands for handling dependencies, repositories, and configurations, as well as utilities for debugging and logging. The cheat sheet serves as a quick reference for users to efficiently manage software packages using APT.

Uploaded by

mysteryrn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

# [ APT Commands ] ( CheatSheet )

1. Installing and Removing Software

● sudo apt install <package_name>: Install a package.


● sudo apt remove <package_name>: Remove a package without removing
dependencies.
● sudo apt purge <package_name>: Remove a package along with its
configuration files.
● sudo apt autoremove: Remove automatically all unused packages.

2. Updating Package Lists and Upgrading Packages

● sudo apt update: Update the list of available packages and their
versions, but it does not install or upgrade any packages.
● sudo apt upgrade: Upgrade all installed packages to the newest available
versions.
● sudo apt full-upgrade: Upgrade packages, removing installed packages if
necessary.
● sudo apt dist-upgrade: Deprecated equivalent of full-upgrade.

3. Searching and Finding Information About Packages

● apt search <term>: Search for a package by name or description.


● apt show <package_name>: Show detailed information about a package.
● apt list --installed: List all installed packages.
● apt list --upgradable: List all packages that can be upgraded.

4. Holding and Unholding Packages

● sudo apt-mark hold <package_name>: Hold a package to prevent it from


being updated.
● sudo apt-mark unhold <package_name>: Unhold a package to allow it to be
updated again.

5. Cleaning and Purging

● sudo apt clean: Clear the local repository of retrieved package files.

By: Waleed Mousa


● sudo apt autoclean: Remove only outdated package files from the local
repository.

6. Working with Repositories

● sudo add-apt-repository <repository>: Add a new repository.


● sudo add-apt-repository --remove <repository>: Remove a repository.
● sudo apt edit-sources: Edit the sources.list file.

7. Fixing Broken Packages

● sudo apt install -f: Fix broken dependencies.


● sudo dpkg --configure -a: Reconfigure unpacked but unconfigured packages.

8. APT Configuration and Preferences

● apt-config dump: Show APT configuration settings.


● apt-config shell: Use APT configuration settings in shell scripts.

9. Downloading Packages Without Installing

● apt download <package_name>: Download the .deb file for a package to the
current directory.

10. Listing and Understanding Dependencies

● apt depends <package_name>: Show raw dependency information for a


package.
● apt rdepends <package_name>: Show reverse dependency information for a
package.

11. Checking the Policy and Priorities

● apt policy <package_name>: Show policy settings, including priority, for


a package.
● apt policy: Show priority of all repositories and packages.

12. Source Packages

● apt source <package_name>: Fetch source files for a package.

By: Waleed Mousa


● sudo apt build-dep <package_name>: Install build dependencies for a
package.

13. Handling Recommended and Suggested Packages

● sudo apt install --no-install-recommends <package_name>: Install without


recommended packages.
● sudo apt install --install-suggests <package_name>: Install suggested
packages.

14. Working with Snapshots and Backups

● aptitude create-state-bundle: Create a snapshot of APT's state.


● aptitude restore-state-bundle <file>: Restore APT's state from a
snapshot.

15. Simulating Commands

● sudo apt install --simulate <package_name>: Simulate installation of a


package.
● sudo apt remove --simulate <package_name>: Simulate removal of a package.

16. Environment Options and Variables

● apt-config shell: Invoke a shell configured for APT.

17. Miscellaneous Operations

● apt moo: An Easter egg command.


● aptitude: Run the aptitude interface, an alternative to apt with some
additional features.

18. Version and Cache Management

● apt-cache policy <package_name>: Show detailed priority selection for a


package.
● apt-cache madison <package_name>: Show available versions of a package in
a table.

19. APT Utilities and Tools

By: Waleed Mousa


● apt-file search <file_name>: Search which package contains a specific
file.
● apt-file list <package_name>: List files contained in a package.

20. APT History and Logs

● cat /var/log/apt/history.log: View APT history.


● cat /var/log/apt/term.log: View APT terminal logs.

21. APT Special Commands

● sudo aptitude: A high-level interface to the package manager


(alternative to apt).
● dpkg -l: List all installed packages with dpkg, the lower-level package
manager.

22. Changing APT Settings

● dpkg-reconfigure <package_name>: Reconfigure an already installed package.

23. Handling Kernel and Modules

● sudo apt install linux-headers-$(uname -r): Install kernel headers.

24. Handling Dpkg Packages

● sudo dpkg -i <package.deb>: Install a .deb package.


● sudo dpkg -r <package_name>: Remove a .deb package.

25. APT and Security

● sudo apt list --installed | grep -i <term>: Check if a specific package is


installed.
● sudo apt-get check: Verify there are no broken dependencies.

26. APT Special Queries

● apt list --manual-installed: List manually installed packages.


● apt list --all-versions <package_name>: List all available versions of a
package.

By: Waleed Mousa


27. APT with Dpkg Queries

● dpkg-query -L <package_name>: List all files provided by a package.


● dpkg-query -W: Show all packages installed in the system.

28. APT Security and Keys

● sudo apt-key list: List trusted keys in APT's keyring.


● sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com
<recv_keys>: Add a new key to the keyring.

29. APT Configuration and Preferences Files

● sudo nano /etc/apt/apt.conf: Edit the main APT configuration file.


● sudo nano /etc/apt/preferences: Edit the APT preferences file for pinning.

30. Holding and Pinning Specific Packages

● echo "<package_name> hold" | sudo dpkg --set-selections: Hold a package


using dpkg.
● echo "<package_name> install" | sudo dpkg --set-selections: Unhold a
package.

31. APT Reporting and Logs

● grep Broken /var/log/apt/term.log: Check the log for broken packages.


● apt list | grep installed: List all installed packages.

32. APT Network Settings and Proxies

● sudo nano /etc/apt/apt.conf.d/01proxy: Configure APT to use a proxy


server.

33. Kernel Packages Management

● sudo apt install --reinstall linux-image-$(uname -r): Reinstall the


current kernel.

34. Managing Services and Daemons

By: Waleed Mousa


● sudo apt install --reinstall <service-package>: Reinstall a service or
daemon package.

35. APT History and User Actions

● less /var/log/apt/history.log: View user actions with APT in a paginated


format.

36. Dealing with Broken or Unmet Dependencies

● sudo apt --fix-broken install: Try fixing broken dependencies.

37. APT and Multi-Arch Support

● dpkg --add-architecture <architecture>: Enable multi-architecture


support.

38. Changing Default APT Options

● sudo nano /etc/apt/apt.conf.d/70debconf: Change default options for APT


interactions.

39. APT Snapshot and Rollback

● aptitude snapshot: Create a snapshot of current packages status


(requires aptitude).
● aptitude rollback: Roll back to a previous snapshot (requires aptitude).

40. APT List Enhancements

● apt list --orphaned: List orphaned packages no longer required by any


installed package.

41. APT Cache and Database Management

● sudo apt-cache stats: Display statistics about the cache.


● sudo apt-cache showpkg <package_name>: Show package records and
dependencies.

42. Enhanced APT Logging

By: Waleed Mousa


● sudo apt -o Debug::pkgProblemResolver=yes install <package_name>: Get
detailed logs for package problem resolving.

43. APT Hooks

● ls /etc/apt/apt.conf.d/: List all APT hooks.

44. APT Mirror Selection

● sudo apt install netselect-apt: Install netselect-apt to find the fastest


mirror.

45. Checking for Held Packages

● dpkg --get-selections | grep hold: Check for any packages on hold.

46. APT in Scripts and Automation

● apt-get -qq update: Quietly update package list, useful in scripts.

47. APT User Interface Adjustments

● aptitude -F %p: Adjust the display format of packages (requires


aptitude).

48. APT Debugging and Troubleshooting

● apt-get -o Debug::Acquire::http=true update: Debug APT's HTTP acquisition


method.

49. APT with Foreign Architectures

● dpkg --print-foreign-architectures: Print foreign architectures added to


dpkg.

50. APT Package and Dependency Exploration

● apt-cache depends <package_name>: View dependencies of a package.


● apt-cache rdepends <package_name>: View reverse dependencies of a
package.

By: Waleed Mousa

You might also like