The apt is the most powerful command-line utility for managing the packages such as installing packages, updating package info, upgrading packages as well as Linux kernel, and removing unused packages in the Linux Debian family. The apt command is a CLI package managing tool that is a combination of apt-get and apt-cache which is more structured and advanced
Aside from installing, updating, and deleting packages, apt command has other features also. In this article, we will be discussing ten apt commands you must know with their examples. To demonstrate these examples I have used the Ubuntu 20.04 LTS system.
Installing Packages with apt
The main purpose of the apt command is to download and install the deb packages. To install the package simply run:
$ sudo apt install package_name
We can install multiple packages with a single command execution, to do so provide package names in a row separated by space one by one.
$ sudo apt install nginx apache2
Updating Package Info and Upgrading Packages with apt
The Linux system actually stores package info instead of the actual package. So every time we hit the update command it will fetch the package info from its source and update the package info to the latest one.
$ sudo apt update
Before upgrading packages make sure you update the package info as Linux doesn’t update it by itself. The upgrade command actually upgrades all installed system software to their latest version if there are any updates.
$ sudo apt upgrade
Remove Installed & Unused Packages with apt command
To remove the installed packages run:
$ sudo apt remove package_name
Then, to remove multiple packages run:
$ sudo apt remove nginx apache2
Similarly, when we remove the packages its dependent package will not be affected and remains as unused packages. So the apt command will identify these unused packages and remove them for us.
$ sudo apt autoremove
Auto removes Unused Packages.
Completely Remove Packages using apt
The earlier package removal command only removes the package but its configuration files remain unaffected. So we can use the following command to remove the package along with the configuration file.
$ sudo apt purge nginx
Removing Package Along With Configuration.
Viewing All Available Deb Packages
You can list out all the packages available in the system packages repository. To do so run:
$ sudo apt list
Similarly, you can view all the system installed packages using the following package.
$ sudo apt list --installed
And also view the list of upgradeable packages by executing,
$ sudo apt list --upgradeable
List of Upgradable Packages.
View Deb Package Information
We can view the additional packages information like version, download size, dependent packages, etc that are stored in our system packages repository maintained by apt command. To know package more about package run,
$ sudo apt show nginx
Viewing Package Additional Information.
Query Packages Using apt
We can query or search specific packages if it is available in the system or not. The apt command searches all packages related to the search keyword.
$ sudo apt search mysql-server
Search Specific Packages.
Install Packages Without Upgrading Packages.
The apt command with --no-upgrade option will install the packages without upgrading the existing packages.
$ sudo apt install apache2 --no-upgrade
Installing Only Updates of Specific Package
If you want to upgrade only a specific existing package you can do so by using the --only-upgrade option to the apt install command. It will only upgrade the packages related to the given packages and prevent the new installation.
$ sudo apt install nginx --only-upgrade
Download Package Using Apt Command
We can download specific packages from their source without installing the packages using apt command. To do so simply run,
$ sudo apt download nginx
Download Deb Package.