Oct 20, 2023 4 min read

apt Command in Linux

Use apt command in linux with our step-by-step tutorial. It is a command-line tool used to install, update, remove, deb packages on Linux.

apt Command in Linux
Table of Contents


Before we discuss apt command in linux, let's briefly understand-What is apt command ?

apt is a command-line tool used to install, update, remove, and manage deb packages on Ubuntu, Debian, and other Linux distributions. It combines the most popular apt-get and apt-cache tool commands with various default values of some options.

The use of apt is intended to be interactive. It is recommended that you use apt-get and apt-cache in your shell scripts, as they are backward compatible between the different versions and have more options and features.

Run the majority of the apt commands as a user with sudo privileges.

You will learn about the basics of apt command in this tutorial.

Updating package index (apt update)

The APT package index is simply a database that keeps track of available packages from the repositories that have been enabled on your system.

Run the command listed below to update the package index. This will retrieve the most recent updates from the APT repositories:

sudo apt update

Package upgrades that require the removal of installed packages are not performed by the command.

If you only want to upgrade a single package, pass the package name:

sudo apt upgrade package_name

Setting up automated security updates is always a good decision.

Full Upgrading (apt full-upgrade)

The difference between an upgrade and full-upgrade is that, if necessary, the latter will remove the installed packages.

sudo apt full-upgrade

Be particularly careful when using this command.

Installing packages (apt install)

You may easily install packages by using the following command:

sudo apt install package_name

Multiple packages can be installed with a single command if you specify them as a list, separated by spaces:

sudo apt install package1 package2

To install local deb files, enter the full path to the file. Otherwise, the script will attempt to retrieve and install the package from the APT repositories.

sudo apt install /full/path/file.deb

Removing Packages (apt remove)

Type the following to uninstall a package that has been installed:

sudo apt remove package_name

Multiple packages can also be specified, separated by spaces:

sudo apt remove package1 package2

The remove command will remove the packages that have been specified, but it can also leave behind some configuration files. Use purge rather than remove to remove the package, including all configuration files:

sudo apt purge package_name

Remove Unused Packages (apt autoremove)

The system will also install the package dependencies if a new package that depends on the other packages is installed. The dependencies will remain on the system even after the package is removed. These unused packages can be removed because they are no longer needed by anything else.

Use the following command to get rid of any unnecessary dependencies:

sudo apt autoremove

Listing Packages (apt list)

You may list the available, installed, and upgradeable packages with the list command.

Use the below command to list all available packages:

sudo apt list

The command will provide a list of all packages along with information on their versions and architecture. Using the grep command, you may filter the output to see if a particular package is installed.

To display only the installed packages, use the following:

sudo apt list --installed

Before actually updating the packages, getting a list of the upgradeable packages could be helpful:

sudo apt list --upgradeable

With the aid of this command, you can look through the list of available packages to find a specific package:

sudo apt search package_name

If a match is found, the command will return the packages whose names match the search term.

Package Information (apt show)

Before uninstalling or installing a new package, knowledge of the package dependencies, installation size, source, and other relevant information may be helpful.

Use the show command to get information about a specific package:

sudo apt show package_name

FAQs on apt Command in Linux

How does the apt command work in Linux?

apt interfaces with the package manager (apt-get or aptitude) to handle software packages. It uses package repositories to fetch information about available packages, handles dependencies, and performs actions like installation and removal.

How do I use the apt command to install a software package?

To install a package, use apt install followed by the package name. For example, apt install package-name.

Can I upgrade all installed packages using the apt command?

Yes, you can upgrade all installed packages using apt upgrade. It fetches updated package information from the repositories and upgrades any outdated packages.

What is the difference between apt update and apt upgrade?

apt update refreshes the local package repository cache, updating the package lists. apt upgrade actually installs newer versions of the packages.

How can I remove a software package using the apt command?

To remove a package, use apt remove followed by the package name. For example, apt remove package-name. If you also want to remove the package's configuration files, use apt purge instead.

Can I search for packages using the apt command?

Yes, you can search for packages using apt search followed by a search term. For example, apt search search-term. It will display matching packages along with brief descriptions.

How do I upgrade the entire Linux distribution using apt?

To upgrade the entire Linux distribution, use apt full-upgrade (or the shorter version apt dist-upgrade). It performs a distribution upgrade, handling package dependencies and system-wide changes.


Understanding how to handle packages is an important aspect of Linux system administration.

apt is a package manager for Debian-based distributions. Open your terminal and run man apt to find out more about the apt command.

If you have any queries, feel free to post a comment below and we'll be happy to answer them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.