This article shows you how to use apt command in Ubuntu, Debain, Linux Mint, or any other Debian or Ubuntu based distributions, with examples so that you can manage packages with easy.
apt is a powerful package management tool that can be used to search, install, update, upgrade, and manage the packages in a Linux operating system. It automatically manages package dependencies, installing required software as needed, and removing it when no longer required.
Table of Contents
- What is apt Command in Linux?
- How to Use apt Command in Linux
What is apt Command in Linux?
apt (Advanced Package Tool) is a command line tool that is used for easy interaction with the
dpkg packaging system in Debian and Debian-based Linux distributions like Ubuntu. It is a collection of tools distributed in a package named
apt, which aim is to simplify the process of managing software.
dpkg is responsible for packing the software in an easy to install package. It is the Debian packages manager. In fact when
apt is used it invoke the
dpkg program to install or remove applications while including additional functions as a dependencies resolution.
In other words,
apt acts as a user-friendly layer that interacts with the
dpkg packaging system.
How to Use apt Command in Linux
Keep in mind, that most of the
apt commands must be run as a user with
Before any operations with
apt, we need to ensure that our local copy of the package database is up-to-date. Without this the system won’t know if there are newer packages available or not.
apt update command downloads up-to-date information about available software packages:
sudo apt update
This download the latest up-to-date software packages and their metadata – package names, version numbers, etc.
List Available Updates
You can view the list of packages that have a newer version ready to be upgraded. For this, run the following command:
apt list --upgradeable
apt list --upgradeable is a hint that is always displayed at the very end of the
apt update output.
apt upgrade will update all the packages that have a new version available. Keep in mind that you need to perform an
apt update before
apt upgrade, so that
apt knows that new versions of packages are available.
sudo apt upgrade
Full System Upgrade
The common difference between
apt upgrade and
apt full-upgrade is that a
full-ugrade will remove the installed packages if that is needed to upgrade the whole system.
This is useful when you want to upgrade from Debian version 10 to 11, for example.
sudo apt full-upgrade
full-upgrade require special care to be used safely, and there’s no good reason even for experienced users to run them routinely.
Installing New Packages
sudo apt install nginx
If you want to install multiple packages at once, for example
firewalld, specify them as a space-separated list:
sudo apt install nginx firewalld
To remove (uninstall) an installed package use the
apt remove command. For example, to remove a package called
sudo apt remove nginx
You can also specify multiple packages, separated by spaces:
sudo apt remove nginx firewalld
We can also easily remove packages with the
apt purge command. The primary difference is that the
apt remove command will uninstall the given packages but it will leave its configuration files behind.
apt purge not only removes the package but also removes all configuration files outside the home directory.
sudo apt purge nginx
In addition, you can also remove all unwanted packages with the following command:
sudo apt autoremove
autoremove option is used to remove packages that were automatically installed to satisfy dependencies for other packages but now are no longer needed as dependencies.
apt search command allows you to search for a given package in the list of the available packages. For example, to search for
nginx packages, enter:
apt search nginx
Searching Through Installed Packages
apt list command displays both installed and packages available to install. What if you want to list specific currently installed packages only? Just pass the
--installed option to the
apt list command. The good news – you can use wildcard (
*) in searches.
For example, to find all the packages currently installed on the system which contains the
nginx within their name run:
apt list --installed nginx*
Get Details About Package
The output of the
apt search command gives you a brief introduction of the packages. If you want more details, use the
apt show command.
apt show nginx
It’s important to note that you need to give the exact package name to the
apt show command. Otherwise the
apt show won’t work.
Knowing how to manage packages with
apt is an essential part of Linux system administration. Of course there is more to
apt but this should get you started.
For more about
apt command in Linux, consult its manual page. As always use the form below for any feedback, questions or suggestion.