Top 20 APT Commands: Your Guide to Ubuntu and Debian Package Management

Package managers are essential tools for managing software on Linux systems, allowing users to install, update, and remove software packages easily. Ubuntu and Debian, two of the most popular Linux distributions, utilize the Advanced Packaging Tool (APT) as their primary package manager. This article will explore the top 20 most common examples of package manager use on Ubuntu/Debian systems, providing detailed steps for each task to help both new and experienced users efficiently manage their systems.

In this tutorial you will learn:

  • How to update your package lists
  • How to install new software packages
  • How to upgrade existing software packages
  • How to remove software packages
  • How to search for software packages
  • How to clean up unused package dependencies
  • How to add a new repository
  • And much more
Top 20 APT Commands: Your Guide to Ubuntu and Debian Package Management
Top 20 APT Commands: Your Guide to Ubuntu and Debian Package Management
CategoryRequirements, Conventions or Software Version Used
SystemUbuntu or Debian based system
SoftwareAPT package manager
OtherInternet connection for downloading packages
Conventions# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

APT vs DPKG

APT (Advanced Package Tool) provides a high-level interface for installing, upgrading, and removing packages along with dependencies from defined repositories. It simplifies package management by handling dependencies automatically. DPKG (Debian Package) is a lower-level tool for managing .deb files directly, without handling dependencies. APT is preferred for ease of use and managing complex dependencies, while DPKG allows direct package file management.

Top 20 Most Common Package Manager Examples on Ubuntu/Debian

Below are detailed examples of how to use the APT package manager for common software management tasks in Ubuntu and Debian systems.

  1. Updating Package Lists: Before installing new packages or upgrading existing ones, it’s crucial to update your package lists.$ sudo apt updateThis command fetches the latest package lists from all configured repositories, ensuring you install the latest versions of packages.
  2. Installing New Software: To install a new software package, use the following command.$ sudo apt install package_nameReplace ‘package_name’ with the name of the software you wish to install. This command downloads and installs the package along with its dependencies.Installing New SoftwareInstalling New Software
  3. Upgrading Installed Packages: Keep your system secure and up-to-date by upgrading all installed packages.$ sudo apt upgradeThis command upgrades all installed packages to their latest versions without removing any packages.
  4. Full Upgrade: A full upgrade can install new packages and remove old ones if necessary.$ sudo apt full-upgradeThis is similar to the upgrade command but can also handle changes in package dependencies with new versions of packages.
  5. Removing Packages: To remove an installed package, use the following command.$ sudo apt remove package_nameReplace ‘package_name’ with the name of the package you want to remove. This command removes the package but leaves configuration files intact.Removing PackagesRemoving Packages
  6. Purging Packages: To remove a package along with its configuration files, use the purge command.$ sudo apt purge package_nameThis is useful when you want to remove all traces of a package from your system.
  7. Searching for Packages: If you’re looking for a package but don’t know its exact name, you can search for it.$ apt search keywordReplace ‘keyword’ with a word related to the package. This command lists all packages that match the search term.Searching for PackagesSearching for Packages
  8. Listing Installed Packages: To see a list of all installed packages on your system.$ apt list –installedThis command displays all packages installed on your system.https://e05a6eac0cf558f0c88c9947709f188d.safeframe.googlesyndication.com/safeframe/1-0-40/html/container.htmlListing Installed PackagesListing Installed Packages
  9. Checking Package Details: To view detailed information about a package.$ apt show package_nameReplace ‘package_name’ with the name of the package. This command displays detailed information about the package, including its version, dependencies, and description.Checking Package DetailsChecking Package Details
  10. Cleaning up Unused Dependencies: After removing packages, unused dependencies may remain on your system. Clean them up with the following command.$ sudo apt autoremoveThis command removes packages that were automatically installed to satisfy dependencies for other packages and are no longer needed.Cleaning up Unused DependenciesCleaning up Unused Dependencies
  11. Identifying Unused Packages with Deborphan: Deborphan is a tool that helps you find orphaned packages, which are installed packages no longer needed by any other installed package. First, install Deborphan if it’s not already installed:$ sudo apt install deborphanOnce installed, run Deborphan to list orphaned packages:$ deborphanThis command will display a list of installed packages that are no longer required by any other package, making it easier to clean up your system by removing unnecessary packages.Identifying Unused Packages with DeborphanIdentifying Unused Packages with Deborphan
  12. Updating Single Package: To update a specific package without upgrading all packages.$ sudo apt install –only-upgrade package_nameReplace ‘package_name’ with the name of the package you wish to update.Updating Single PackageUpdating Single Package
  13. Downloading Package Without Installing: To download a package without installing it.$ apt download package_nameReplace ‘package_name’ with the name of the package. This command downloads the .deb package file to your current directory.
  14. Checking for Broken Dependencies: To check for and fix broken dependencies.$ sudo apt -f installThis command checks for and attempts to correct any broken dependencies on your system.
  15. Listing Upgradable Packages: To list all packages that can be upgraded.$ apt list –upgradableThis command displays a list of packages with available updates.
  16. Finding Package Providers: To determine which package provides a specific file or command, use the following command.$ dpkg -S keywordReplace ‘keyword’ with the file name or command you’re interested in. This command searches through all installed packages to find which one contains the specified file or command, helping you track down specific functionalities or dependencies.
  17. Checking Package Dependencies: To view the dependencies of a specific package before installation, you can use the following command.$ apt depends package_nameReplace ‘package_name’ with the name of the package you’re interested in. This command displays a list of all packages that the specified package depends on, helping you understand its requirements and potential impact on your system.
  18. Searching for Package Providers: To find out which available package provides a specific file or command, not limited to those installed on your system, use the apt-file tool. First, ensure apt-file is installed:$ sudo apt update && sudo apt install apt-fileThen, update apt-file’s database:$ sudo apt-file updateFinally, search for the package providing the file or command:$ apt-file search keywordReplace ‘keyword’ with the name of the file or command you’re interested in. This command scans all packages in the repositories, identifying which package provides the file or command in question.
  19. Installing Local Package Files: If you have a local .deb package file and wish to install it directly, you can do so using the APT command.$ sudo apt install ./my_package.debReplace ‘./my_package.deb’ with the path (relative or absolute) to your local package file. This command allows APT to handle the installation of local .deb files, resolving and installing any dependencies from the repositories if necessary.
  20. Listing All Installed Packages: To generate a list of all software packages installed on your system, use the command below.$ dpkg –listThis command utilizes ‘dpkg’, Debian’s package management program, to display a comprehensive list of installed packages, providing valuable insights into the software currently on your system.

Conclusion

Managing software packages on Ubuntu and Debian systems is straightforward with the APT package manager. By mastering the commands listed in this article, users can efficiently manage their system’s software, ensuring it remains up-to-date and secure. Whether you’re installing new software, upgrading your system, or cleaning up unused packages, APT provides the tools you need to maintain your system with ease.

LEAVE A RESPONSE