Linux APT Command in Examples for Ubuntu, Debian, Mint Users

Learn how to use the APT command in Linux with this helpful guide to install, update, and remove software packages like a pro.

Linux is a powerful operating system that offers various tools for managing software packages. The APT (Advanced Package Tool) command is one of the most popular.

So, if you are a Debian, Ubuntu, or Linux Mint user, APT allows you to easily install, update, and remove software packages from your Linux system.

However, for beginners, APT can be overwhelming. That’s why we’ve put together this article to provide real-world examples of how to use the APT command in Linux.

Whether you’re a novice or an experienced Linux user, these examples will help you to master the APT command and simplify your package management tasks. So, let’s dive in and explore the power of APT!

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, aiming to simplify the process of managing software.

At the same time, dpkg, the Debian packages manager, is responsible for packing the software in an easy-to-install package. So, when apt is used, it invokes 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. It is a powerful package management tool that can be used to search, install, update, upgrade, and manage packages in Ubuntu, Debian, Linux Mint, or any other Debian or Ubuntu-based distributions.

In addition, it automatically manages package dependencies, installing required software as needed and removing it when no longer required.

How to Use APT Command in Linux

Remember that most of the apt commands must be run by a user with sudo privileges.

Fetch Updates

Before any operations with apt, we must ensure that our local copy of the package database is up-to-date. Without this, the system won’t know whether newer packages are available.

The apt update command downloads up-to-date information about available software packages:

sudo apt update
Fetch updates.
Fetch updates.

This downloads 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 apt command:

apt list --upgradeableCode language: PHP (php)
List available updates.
List available updates.

apt list --upgradeable is a hint always displayed at the end of the output of the apt update command.

Upgrade Packages

Running an apt upgrade will update all the packages that have a new version available. Remember that you need to perform an apt update before the apt upgrade command so that apt knows that new versions of packages are available.

sudo apt upgrade
Upgrade packages.
Upgrade packages.

Full System Upgrade

The common difference between an apt upgrade and an apt full-upgrade is that a full-upgrade will remove the installed packages if needed to upgrade the whole system.

For example, this is useful when upgrading from Debian version 10 to 11.

sudo apt full-upgrade
Full system upgrades with APT.
Full system upgrades with APT.

Commands with 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

Installing a new package is one of the most common uses of the apt command. So, once your packages database is updated, you can install any packages with the apt install. For example, let’s install Nginx Web Server:

sudo apt install nginx
Installing new packages with the APT command.
Installing new packages with the APT command.

If you want to install multiple packages at once, for example, nginx and firewalld, specify them as a space-separated list:

sudo apt install nginx firewalld
Installing multiple packages with the APT command.
Installing multiple packages with the APT command.

Simulating Installation

There are situations when you want to know in advance which packages the apt command will install on your system. In these cases, the “-s” option comes in handy because it allows you to simulate an actual installation by showing the full list of actions that apt will execute without actually performing any of them.

For example, simulating the installation of the “lighttpd” package looks like this:

sudo apt install lighttpd -s
Simulate a package installation with APT.
Simulate a package installation with APT.

Removing Packages

To remove (uninstall) an installed package, use the apt remove command. For example, to remove a “nginx” package, enter the following apt command:

sudo apt remove nginx
Remove packages.
Remove packages.

You can also specify multiple packages, separated by spaces:

sudo apt remove nginx firewalld
Remove multiple packages.
Remove multiple packages.

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, leaving its configuration files behind.

Whereas apt purge not only removes the package but also removes all configuration files outside the home directory.

sudo apt purge nginx
Remove packages.
Remove packages.

Remove Unused Dependencies

When a package is installed, the APT package manager automatically installs any additional packages required to function correctly. These additional packages are known as dependencies.

However, as software is updated and removed, dependencies can accumulate on the system, which is no longer needed by any installed packages.

The apt autoremove command will remove any packages automatically installed as dependencies for other packages that are no longer needed. This way, you free up disk space and reduce clutter in the system.

sudo apt autoremove
Autoremove unused packages with the APT command.
Autoremove unused packages with the APT command.

Additionally, to remove packages alongside their associated configuration files, add the “--purge” option to the command.

sudo apt autoremove --purge

Searching Packages

The apt search command allows you to search for a given package in the list of available packages. For example, to search for nginx packages, enter:

apt search nginx
Search for a package with APT.
Search for a package with APT.

Searching Through Installed Packages

The 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 is you can use a wildcard (*) in searches.

For example, to find all the packages currently installed on the system which contain the nginx within their name, run:

apt list --installed nginx*Code language: PHP (php)
Searching through installed packages.
Searching through installed packages.

Get Details About Package

The output of the apt search command gives you a brief introduction to the packages. If you want more details, use the apt show command.

apt show nginx
Show details about a package.
Show details about a package.

It’s important to note that you must give the exact package name to the apt show command. Otherwise, the apt show won’t work.

Bottom Line

In this article, we have explored some of the most commonly used APT commands and provided examples of how to use them effectively. By mastering APT, users can streamline their package management workflow and keep their system up-to-date and secure.

Its simple and easy-to-use syntax allows users to quickly install, update, remove, and manage software packages and their dependencies. Of course, there is more to APT, but this should get you started.

In conclusion, we would like to add that besides the direct interaction with APT, users can also use Nala – a prettier frontend for the APT command that offers some enhanced features.

For more about the APT command in Linux, consult its manual page. Use the form below for feedback, questions, or suggestions.

Bobby Borisov

Bobby Borisov

Bobby, an editor-in-chief at Linuxiac, is a Linux professional with over 20 years of experience. With a strong focus on Linux and open-source software, he has worked as a Senior Linux System Administrator, Software Developer, and DevOps Engineer for small and large multinational companies.

Think You're an Ubuntu Expert? Let's Find Out!

Put your knowledge to the test in our lightning-fast Ubuntu quiz!
Ten questions to challenge yourself to see if you're a Linux legend or just a penguin in the making.

1 / 10

Ubuntu is an ancient African word that means:

2 / 10

Who is the Ubuntu's founder?

3 / 10

What year was the first official Ubuntu release?

4 / 10

What does the Ubuntu logo symbolize?

5 / 10

What package format does Ubuntu use for installing software?

6 / 10

When are Ubuntu's LTS versions released?

7 / 10

What is Unity?

8 / 10

What are Ubuntu versions named after?

9 / 10

What's Ubuntu Core?

10 / 10

Which Ubuntu version is Snap introduced?

The average score is 68%