The apt command in Linux – A Complete Reference

If you have installed software on your Linux system using the terminal then you must have come across apt-get install. This tutorial will explain what the command means and what’s the right way to use it. Let’s get started.

What is apt?

Apt stands for “Advanced Packaging Tool”. It is a package manager that is used for managing the installation, updating, and removal of software packages in a Debian based Linux system.

A Debian based Linux system uses dpkg packaging system. Dpkg is responsible for packing the software in an easy to install package. Apt-get acts as a user-friendly tool that interacts with this packaging system.

While installing a software you must have also come across the following command :

sudo apt update

What does this statement do? Let’s try and answer this question next.

How to use the apt command in Linux?

Let’s go over the functions offered by the apt command in Linux.

1. Update Package Database

All the packages you install on your system are referenced from a common database. The command sudo apt update is responsible for updating this database.

Apt Update
Apt Update

Here the words Hit, Ign, Get and Err have the following meanings:

  • Hit: there is no change in the package version.
  • Ign: the package is ignored.
  • Get: A new version of the package is available. It downloads the information about the new version of the package.
  • Err: There is some error in retrieving information about the package.

Most of the apt-get commands require administrative privileges. This is why apt get commands are run with sudo.

2. Installing a new package

If you know the name of the package you want to install you can install it using the command:

sudo apt install [package name]

You can also install multiple packages using a single command. The syntax for that is:

sudo apt install [package name 1] [package name 2]...

Let’s try and install nano editor using the command above.

sudo apt install nano
Apt Install Nano

Alternatively you can also use sudo apt-get install to install packages.

sudo apt-get install
Sudo Apt Get Install Nano
Sudo Apt Get Install Nano

2.1. What’s the difference between apt and apt-get?

Apt is a newer version of apt-get. Visually one of the major differences is that the apt command gives an additional progress bar while installing packages.

Spell Check 1

The functions in the apt-get command have been combined into the apt command and made more user-friendly.

apt-get command is still active for backward compatibility. As a best practice, you should start using apt instead of apt-get to install/update/remove packages. Read through this article to understand the difference between apt and apt-get.

3. Upgrading a package in Linux

Running a sudo apt upgrade will update all the packages that have a new version available. This information about the availability of a new version is taken from the common database. That is why it is advisable to run sudo apt upgrade to keep the database up-to-date.

sudo apt upgrade
Apt Upgrade
Apt Upgrade

Before updating the packages it will tell you about the memory needed for the updates and ask you whether you want to continue with the updates.

4. Uninstall a package using the apt command

You can use apt get to uninstall packages as well. The command to uninstall a package is :

sudo apt remove [package name]

Let’s try the following command to remove the nano editor:

sudo apt remove nano
Apt Remove Nano
Apt Remove Nano

Press ‘y‘ if you want to continue.

Uninstall Nano

5. Search for packages

Apt also lets you search for packages in the database. Search is performed using apt search <package name>. The command to search for a package using apt

apt search [keyword]

Let’s try and get the list of Firefox packages using the command above.

apt search firefox
Apt Search
Apt Search

You can compare this to the old apt-get output. The command for searching using apt-get is :

apt-cache search firefox
Search Firefox

Conclusion

This tutorial was about apt command in Linux. Hope you had fun learning with us.