Before you understand the APT command, you need to understand what is a package manager? in the Operating System world.
The package manager is a utility to manage the application in your Operating System by installing, removing and updating. Examples of package managers are Winget (for Windows), and Homebrew (for Mac).
APT stands for Advanced Packaging Tools and helps you to handle your applications and packages on Debian-based distributions such as Ubuntu, Pop!_OS, Kali Linux, Linux Mint, etc.
Other Linux distributions, such as RedHat, Fedora, Arch, and Manjaro comes with different package manager such as rpm, DNF, yay, etc.
Note: Managing application using the apt command require the root access or account with sudo permission.
Table of Contents
Updating Package Database with APT Command
Usually, in Linux distributions, we have text files known as package database containing the record of the current release of all the applications located at /etc/source.list fetched from the official repository provided by your Linux distribution.
This database should be updated regularly in order to get the latest release information of the application from the official repository of your Linux distribution.
Use the below command to update your local system package database.
$ sudo apt update
Once the above command is executed, your local database containing the information of the current release of the package will be updated.
Next time, when you upgrade or install the new application the version of the application will be decided based on the current package information on your local package database.
Upgrading Packages with APT Command
Upgrading the system will upgrade all the systems and manually installed applications to their latest release by finding the release information from your local package database.
This also includes the latest security patches and fixes to improve the security of your system.
It’s always good to hit the apt update
command to get the latest application release information before upgrading your system using the below command.
$ sudo apt upgrade
However, if you are not interested in updating your whole system packages, you can manually upgrade the specific application by specifying the name with the apt upgrade
command as shown below.
$ sudo apt upgrade [YOUR_PACKAGE_NAME]
The package will be upgraded if new release information is available in the local package database otherwise remains the same.
Full Upgrade your System with APT Command
apt update
and apt full-upgrade
are almost identical except in full-upgrade your complete system will be upgraded with the packages required to remove.
This might result in a boot failure or package crash, always make sure to back up your system or important files before upgrading your system using the below command.
$ sudo apt full-upgrade
Searching Packages with APT Command
You can easily search for packages available for your Linux distribution. These packages are those packages listed in your local package database fetched from your Linux distribution repository.
To search for any package available to install in your Linux system, use apt search
along with the package name as shown below.
$ sudo apt search [PACKAGE_NAME]
If the record for the application is found in the local package database then it will be listed with other details.
Installing Packages with APT Command
Once you found the record of your package with its name and context using the apt search
command, you can easily install it using the apt install
command with your package name as shown below.
$ sudo apt install [PACKAGE_NAME]
You can even install multiple packages at the same time. Just separate each package with space.
$ sudo apt install [PACKAGE_ONE] [PACKAGE_TWO] [PACKAGE_THREE]
Removing Packages with APT Command
The package can be removed using the multiple ways with and without the configuration files to know more check the below link.
The Right Way to Remove Apt, Deb, Snap, and Flatpak Packages on Ubuntu
Use the below command to remove the package installed using the apt command without removing its configuration file.
$ sudo apt remove [PACKAGE_NAME]
Use the below command to remove the package installed using the apt command including its configuration file.
$ sudo apt purge [PACKAGE_NAME]
Listing Local Packages with APT Command
There is not a straightforward way to list all the current installed packages in your system. Either it will display the preinstalled and manually installed application or a custom installed application by you. To know more visit the below link.
List all Installed Packages on Ubuntu and Debian-based Linux Distributions
Use the below command, to list all the installed packages with the dependencies.
$ sudo apt list
Use the below command, to list the specific package or dependencies by piping the grep command with the apt list
.
$ sudo apt list | grep [PACKAGE_NAME]
Use the below command, to list the custom installed application by you in your system.
$ sudo apt list --installed
Use the below command, to list the current upgrade available packages based on your local package database.
$ sudo apt list --upgradeable
Display the Package Information with APT Command
To know more about the package origin information such as package maintainer, version, source, download size, dependencies depending on that package, and description can be displayed using the apt show
command.
Use the below command, to retrieve all the information about the specific package.
$ sudo apt show [PACKAGE_NAME]
Wrap Up
Always update your local package database before doing anything using the apt update
command.
Upgrade your system once a week to get the latest version of the application and security updates using the apt upgrade
command.
Whenever a new release of your Linux distribution comes, execute the apt full-upgrade
command.
To search for an application, use the application name with the apt search
command.
To know more about the application, specify the application name with the apt show
command.
To install the application, specify the name with the apt install
command.
If you want to remove the installed package, specify the name of the package with the apt remove
or apt purge
command.
Innovative tech mind with 12 years of experience working as a computer programmer, web developer, and security researcher. Capable of working with a variety of technology and software solutions, and managing databases.