It is one of the available package managers along with apt-get but like others it allows you to install, modify or remove different packages without building them from source code. It can do much more actions related to package management which we’re going to cover in the next sections. The general syntax of using apt command follows: Remember to use sudo with apt, as many of its sub-commands would require the privilege to make system-level changes. Here we’ll be covering different sub-commands that you can use with apt and their use.

Update Package Database

apt needs a repository of packages with a database of all available packages that can be installed on a Debian/Ubuntu system. This repository database should be updated before you begin to install a package as apt should know the details about the package, its version, architecture, and remote location. Updating the repository database is easy and can be done with: Example:

Upgrade Installed Packages

Installed packages on a system can be upgraded to the latest available version using: With upgrade command, packages will be installed if required to satisfy dependencies, but existing packages will never be removed. If an upgrade for a package requires the removal of an installed package then an upgrade for this package isn’t performed. Example: Make sure you’ve executed sudo apt update before you upgrade your packages to avoid issues during the upgrade as well as to ensure you get the latest available packages from the repository. If you want, you can run these commands in a single line as:

Full-Upgrade Packages

apt also offers a full-upgrade command. It differs from upgrade command as it will remove currently installed packages if this is needed to upgrade the system as a whole. As such be careful with this command and if possible, go with the upgrade command instead.

Install Single Package

Installing a new package can be done with apt by using the below syntax: Example:

Install Multiple Packages

You can install multiple packages on a system with apt. It follows a similar syntax as in the previous example: Example: If one of the specified packages is already installed on the system, apt will look for an update in a repository and if available will upgrade the package or else will keep the installed version as it is.

Install Specific Version

Often you need to install a specific version of a package especially while on enterprise systems. apt allows you to install a given version of a package assuming its available in the repository using: Example:

Remove a Package

Like installing a package, apt can be used to remove a package from a system with the below command: Example:

Purge a Package

Like removing a package, purging a package also does the same task but while with remove command apt just removes the binaries of a package leaving the configuration files as it is. On the other hand, purge command ensures that everything related to the package including its binaries and configuration files is removed from the system. Leaving the configuration files allows you to reuse the same configuration files again if you plan to reinstall the application. To purge a package, use: Example:

Search for Packages

apt can not only serve as the utility to install and remove packages. It can also search the required package in the repository with search command as: Example:

View Package Content

To get details about a package, whether it is installed or to be installed, you can use show command as given below: Example:

List Installed Packages

We often need to list installed packages on a system for different purposes. apt allows you to get the list of installed packages simply with:

List All Packages

To list all packages available for your system, use list command with –all-versions keyword as:

List Upgradable Packages

Packages need to be kept up-to-date as new versions keep releasing with improved or additional features and bug fixes including critical security loopholes. apt ensures you can patch your Debian/Ubuntu system easily with upgrade command as suggested earlier in the article. To list all available upgrades for installed packages on your system, run: Example:

Clean Unused Packages

With normal usage, sometimes your system may have packages installed that are no longer required. It may happen as these packages were installed as part of the dependency of another package which has already been removed later though the dependencies are left lingering on the system. To clean such packages and free up some disk space you can use: Example: My system didn’t have any leftover packages, so the output reported no changes.

Check Package Dependencies

A package may have one or more dependencies that must be installed on a system for the package to work correctly. apt ensures required dependencies are installed as part of package installation. If you want to check dependencies of a package, use: Example:

Reinstall a Package

A package may get corrupted or you may need to reinstall it to ensure all package files are in the right order. To install a package again without removing it first you can use: Example:

Download a Package

Package files can be downloaded to the local filesystem without installing them. To download a package with apt, use: Example:

Check Package Changelog

We can easily check the changelog about any package with apt by using:

Edit Sources

apt‘s edit-sources command lets you edit your sources.list files while also providing sanity checks to ensure the changes are consistent and valid. This is a work-in-progress command and hence should be used with care. You can edit sources.list as :

Get APT Help

To get more help about apt command, use: Example:

Summary

apt tool is a handy and powerful CLI-based package management utility for Debian/Ubuntu-based systems. A system administrator’s normal day-to-day job involves managing packages on a system and knowing apt and its common usage commands make this task easy. For further help on apt, refer to its man page.

20 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 2020 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 220 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 1920 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 8020 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 4520 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 4020 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 4220 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 8120 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 5620 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 6420 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 1420 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 6020 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 6920 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 6620 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 6720 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 7420 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 3220 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 2020 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 6920 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 4120 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 3620 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 7020 apt Command to Know as Sysadmin to Manage Ubuntu or Debian Packages - 7