Linux APT Command in Examples for Ubuntu, Debian, Mint Users (2024)

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!

Table of Contents

[Open][Close]

  • What is APT Command in Linux?
  • How to Use APT Command in Linux
    • Fetch Updates
    • List Available Updates
    • Upgrade Packages
    • Full System Upgrade
    • Installing New Packages
    • Simulating Installation
    • Removing Packages
    • Remove Unused Dependencies
    • Searching Packages
    • Searching Through Installed Packages
    • Get Details About Package
  • Bottom Line

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.

Theapt updatecommand downloads up-to-date information about available software packages:

sudo apt update
Linux APT Command in Examples for Ubuntu, Debian, Mint Users (1)

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)
Linux APT Command in Examples for Ubuntu, Debian, Mint Users (2)

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

Upgrade Packages

Running anapt upgradewillupdate all the packagesthat 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
Linux APT Command in Examples for Ubuntu, Debian, Mint Users (3)

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
Linux APT Command in Examples for Ubuntu, Debian, Mint Users (4)

Commands withfull-upgraderequire 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
Linux APT Command in Examples for Ubuntu, Debian, Mint Users (5)

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
Linux APT Command in Examples for Ubuntu, Debian, Mint Users (6)

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
Linux APT Command in Examples for Ubuntu, Debian, Mint Users (7)

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
Linux APT Command in Examples for Ubuntu, Debian, Mint Users (8)

You can also specify multiple packages, separated by spaces:

sudo apt remove nginx firewalld
Linux APT Command in Examples for Ubuntu, Debian, Mint Users (9)

We can also easily remove packages with the apt purgecommand. 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
Linux APT Command in Examples for Ubuntu, Debian, Mint Users (10)

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
Linux APT Command in Examples for Ubuntu, Debian, Mint Users (11)

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
Linux APT Command in Examples for Ubuntu, Debian, Mint Users (12)

Searching Through Installed Packages

Theapt list commanddisplays 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 thenginxwithin their name, run:

apt list --installed nginx*Code language: PHP (php)
Linux APT Command in Examples for Ubuntu, Debian, Mint Users (13)

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
Linux APT Command in Examples for Ubuntu, Debian, Mint Users (14)

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 theAPTcommand in Linux, consult itsmanual page. Use the form below for feedback, questions, or suggestions.

Linux APT Command in Examples for Ubuntu, Debian, Mint Users (2024)
Top Articles
Latest Posts
Article information

Author: Frankie Dare

Last Updated:

Views: 6422

Rating: 4.2 / 5 (53 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Frankie Dare

Birthday: 2000-01-27

Address: Suite 313 45115 Caridad Freeway, Port Barabaraville, MS 66713

Phone: +3769542039359

Job: Sales Manager

Hobby: Baton twirling, Stand-up comedy, Leather crafting, Rugby, tabletop games, Jigsaw puzzles, Air sports

Introduction: My name is Frankie Dare, I am a funny, beautiful, proud, fair, pleasant, cheerful, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.