How To Use Apt Command.
This guide serves as a quick reference for the apt commands.
Most of the apt commands must be run as a user with sudo privileges.
apt is a command-line utility for installing, updating, removing, and otherwise managing deb packages on Ubuntu, Debian, and related Linux distributions. It combines the most frequently used commands from the apt-get and apt-cache tools with different default values of some options.
Updating package index (apt update)
The APT package index is basically a database that holds records of available packages from the repositories enabled in your system.
To update the package index run the command below. This will pull the latest changes from the APT repositories:
Always update the package index before upgrading or installing new packages.
Upgrading packages (apt upgrade)
Regularly updating your Linux system is one of the most important aspects of overall system security.
To upgrade the installed packages to their latest versions run:
The command doesn’t upgrade packages that require removal of installed packages.
If you want to upgrade a single package, pass the package name:
It is always a good idea to configure automatic security updates .
Full Upgrading (apt full-upgrade)
The difference between upgrade and full-upgrade is that the later will remove the installed packages if that is needed to upgrade the whole system.
Be extra careful when using this command.
Installing packages (apt install)
Installing packages is as simple as running the following command:
If you want to install multiple packages with one command, specify them as a space-separated list:
To install local deb files provide the full path to file. Otherwise, the command will try to retrieve and install the package from the APT repositories.
Removing Packages (apt remove)
To remove an installed package type the following:
You can also specify multiple packages, separated by spaces:
The remove command will uninstall the given packages, but it may leave some configuration files behind. If you want to remove the package including all configuration files, use purge instead of remove :
Remove Unused Packages (apt autoremove)
Whenever a new package that depends on other packages is installed on the system, the package dependencies will be installed too. When the package is removed, the dependencies will stay on the system. This leftover packages are no longer used by anything else and can be removed.
To remove the unneeded dependencies use the following command:
Listing Packages (apt list)
The list command allows you to list the available, installed and, upgradeable packages.
To list all available packages use the following command:
The command will print a list of all packages, including information about the versions and architecture of the package. To find out whether a specific package is installed, you can filter the output with the grep command.
To list only the installed packages type:
Getting a list of the upgradeable packages may be useful before actually upgrading the packages:
Searching Packages (apt search)
This command allows you to search for a given package in the list of the available packages:
If found, the command will return the packages which name matches the search term.
Package Information (apt show)
The information about the package dependencies, installation size, the package source, and so on might be useful before removing or installing a new package.
To retrieve information about a given package, use the show command:
Knowing how to manage packages is an essential part of Linux system administration.
apt is a package manager for debian based distributions. To learn more about the apt command open your terminal and type man apt.