Apt Package Manager [A Complete Guide on How to Use it]

In Debian-based distributions, the installation and removal of software are generally managed through the package management system known as the Advanced Package Tool (APT). It uses the tools to manage, update, install, and uninstall software packages. In this article, I will illustrate the apt package manager in detail and hope that will help the user to use the package manager efficiently.

Table of Contents

What is APT Package Manager in Linux?

APT (Advanced Package Tool) is a tool that facilitates the process of installation, uninstallation, and updation of Linux software packages. It is also capable of maintaining, and upgrading the packages. APT handles the .deb packages which use the apt, and apt-get tools by default to manage the operating system. It is the front-end package manager for the back-end dpkg. For that reason, it simplifies management and is also user-friendly and interactive for the user.

The Key Components of APT

The users who use the package manager for the first time should know about the key components of apt. Here I have shown the modules:

  1. Usage: Primarily used in Debian and Ubuntu, front end for low-level dpkg packages.
  2. File extension: The file extension for the APT package manager is .deb.
  3. Tools: apt-get, apt, and other APT-related commands.
  4. Key Features: Dependency resolution, Easy automatic package management and upgrade repository handling, Invoke the dpkg backend.
  5. Dependency Handling: Resolving dependencies automatically and installing required packages.

Why Use the APT Package Manager?

Some key features make APT the most usable package manager in Debian-based distribution. Below I have shown some of them:

  • User-Friendly: Apt provides a user-friendly interface which includes the progress bar, and interactive mode. It is easy to use for the beginner.
  • Pinning Feature: Apt provides the pinning feature. It helps one install different versions of packages from different repositories. It also prevents upgrading to avoid conflict when more than two packages use the same dependencies.
  • Available flag: Apt provides additional flags like -y or –yes and -s or –simulate option. -y option means yes to all the transactions and prompts and the -s option means to simulate the changes that a particular command has done.
  • Customization: Apt has higher customization. If one wants to configure according to their need then he can edit the /etc/apt/apt.conf file.

Package Management With APT

Managing packages means installing, removing, searching, handling a repository, and showing information about a package. Below I will illustrate the management of packages to provide a clear view on how to use the APT package manager in Linux:

Install Packages With APT on Ubuntu

The common function of any package manager is to install a package. apt shows variety in installation. With apt, you can install single packages, multiple packages, and deb files. Here you can see some of the installation commands below.

A. How to Install Single Package

To install a single package you can copy the following command on Ubuntu:

sudo apt install curl
EXPLANATION
  • sudo: Permits administrative privileges.
  • apt: Provides a high-level command line interface for the package management system.
  • install: Command installs the specified package.
  • curl: Package name which I want to install.

Install package with apt

Showing the progress bar

From the images, you can see the progress bar at the bottom which shows the progress in percentage (80%). I have installed a package named curl you can choose any package according to your preference.

B. How to Install Multiple Packages With APT

With apt you can install multiple packages with one command. So here I have shown how one can install multiple packages at the same time. If you want to practice you can copy the following command:

sudo apt install gedit apache2 vlc
EXPLANATION
  • gedit apache2 vlc: Packages that I want to install.

Install multiple packages with apt

From the image, you can see all the packages installed simultaneously.

C. How to Install .deb Package Locally

If you want to install a deb file then you have to download the deb file to your system. From the image, you can see the file is already downloaded to my system.

Showing the manually downloaded file

After downloading the file you can install the file by using the following command:

sudo apt install /home/oishi/Downloads/teamviewer_15.21.4_amd64.deb
EXPLANATION
  • /home/oishi/Downloads/teamviewer_15.21.4_amd64.deb: The path where the downloaded file is located.

Locally install a package with apt

D. How to Install a Specific Version of the Package in Ubuntu

If you want to install a specific version, you can do this with apt. To do this you can copy this command:

sudo apt install apache2=2.4.55-1ubuntu2
EXPLANATION
  • apache2: The package that I want to install.
  • 4.55-1ubuntu2: The specific version I want to install.

Install specific version of package

Remove Packages Using APT

Sometimes you install a package but later you do not need the file anymore. So you can uninstall or remove it with the remove option. In this section, I have shown how to remove a single package and unnecessary packages.

1. How to Remove a Single Package in Ubuntu

To remove a package you can copy the command:

sudo apt remove gedit
EXPLANATION
  • remove: Remove the desired package from the repository.
  • gedit: The package that I want to remove.

Remove a single package with apt

I have removed gedit package you can choose any package you can use other packages according to your liking.

2. How to Remove Multiple Packages With APT

To uninstall multiple packages at the same time you can copy the following command on Ubuntu:

sudo apt remove apache2 gedit vlc
EXPLANATION
  • apache2, gedit, vlc: The packages that I want to remove.

Remove multiple packages with apt

3. How to Remove Unnecessary Packages Using APT Package Manager

There are many unnecessary packages installed in the system as dependencies which creates potential issues and also uses disk space. To uninstall any dependency packages that are not required by any installed packages, in Ubuntu, you can copy this command:

sudo apt autoremove
EXPLANATION
  • autoremove: Uninstall any dependency that is not required by any installed packages.

Remove unnecessary packages with apt

Uninstall with Configuration File Using APT

When you want to uninstall a package with its configuration files, you have to use the purge option to remove the package with its configuration file. Below I have shown how one can purge single and multiple packages.

A. How to Purge a Single Package in Ubuntu

you can copy the command on Ubuntu to purge a package:

sudo apt purge apache2
EXPLANATION
  • purge: Remove a package with its configuration file
  • apache2: The package that I want to remove with the configuration file.

Purge a package with apt

B. How to Purge Multiple Packages Using APT

If you want to purge multiple packages at the same time then you can use the following command:

sudo apt purge apache2 gedit vlc
EXPLANATION
  • apache2, gedit, vlc: The packages that I want to remove with the configuration file.

Purge multiple packages

Reinstalling Packages With APT

When you want to install the failed packages that have been not installed you can reinstall the package with the following command on Ubuntu:

sudo apt reinstall vlc
EXPLANATION
  • reinstall: Reinstall the failed or removed packages
  • vlc: The package that I want to reinstall.

Reinstall a package with apt

Update and Upgrade Packages

One important function of a package manager is to update the packages. With apt, you can update the full system and also single and multiple packages. Here below I have shown how to use the update command:

1. Update Packages With APT

With the apt tool when you use the update command it also shows how many packages can be upgraded. You can copy and run the following command on Ubuntu:

sudo apt update
EXPLANATION
  • update: Command to make packages up to date.

Update all packages with apt

From the image you can see, that 123 packages can be upgraded. You can also see the upgradable package list.

2. Upgrade Installed Packages on Ubuntu

Here is the command to see the list of the packages that need to be upgraded. You can copy the command from here:

sudo apt list  --upgradable
EXPLANATION
  • list: Shows the list of the following command.
  • upgradable: Upgradable package.

Upgradable package list

From the above image, you can see as I run the command it shows the list of the upgradable packages.

Now you can upgrade the package list that can be upgraded with the following command:

sudo apt upgrade
EXPLANATION
  • upgrade: Download the upgraded version.

Upgrade all packages

3. Specific Package Upgrade Using APT

If you want to upgrade a specific package then you can copy the following command on Ubuntu:

sudo apt upgrade nano
EXPLANATION
  • nano: Package I want to upgrade.

Upgrade a specific package

4. Dist-upgrade for a Full Distribution Upgrade

The apt upgrade command upgrades all the installed packages except for the packages that create conflict for their dependencies. To upgrade these kinds of packages you can copy the following command:

sudo apt dist-upgrade
EXPLANATION
  • dist-upgrade: Upgrade the distribution to the upgraded version.

Upgrade all packages with dependencies

Show the List of Packages With APT

Sometimes users need to know the list of packages, the list of installed packages, and whether a specific package has been installed or not. So I will show this list of packages with the apt command below:

A. View All Package Lists Using APT Package Manager

If you want to see the list of all packages that are available in the system you can copy the following command:

sudo apt list
EXPLANATION
  • list: Shows all the packages in the system.

List all of the packages with apt

With this command, you will see a huge list of packages as it shows all the installed, available installation packages on the system.

B. View All the Installed Package List

If you want to see the .deb packages that you have installed locally then copy the following command on Ubuntu:

sudo apt list --installed
EXPLANATION
  • list – -installed: List of installed packages.

Display all the installed packages

From the image, you can see the packages that I have installed earlier and installed locally.

C. Find Which Packages Are Installed

To see if a package is installed or not with apt you can copy the following command on Ubuntu:

sudo apt -qq list nano
EXPLANATION
  • -qq: Option to query the following package.
  • list: Shows the list of the following package.
  • nano: The package that I want to check.

You can use -q option instead of -qq option. It will show the same output.

Query for a package with apt

From the image, you can see the package nano which I checked has been installed already.

You can also use list – -installed to see if one specific package is installed or not. To do that you can copy the following command:

sudo apt list --installed | grep nano
EXPLANATION
  • (|) pipe: Creates a unidirectional data channel that can be used for interprocess communication.
  • grep: Command-line for searching a file with a particular pattern.
  • nano: The package name that I want to see.

Checking a package whether it is installed or not

Show Package Version Repository Information

If you want to see a specific package version and repository from which it belongs to then you can use the following command:

sudo apt policy nano
EXPLANATION
  • policy: Display the package version and repository.
  • nano: The package which I want to know about the version repository.

View version and repository information with apt

From the above image, you can see the version and repository have been shown.

Search the Package Using APT Package Manager

When one needs to search a package in the repository he can locate the package with the search command. You can copy the following command on Ubuntu to search for a package:

sudo apt search zfs
EXPLANATION
  • search: Locate a package in the repository.
  • zfs: The package that I searched for.

Search a package with apt

Here I have searched zfs package you can choose any package according to your needs.

View Package Details

To view all the information about a package such as version, package name, and origin you can use the show option which will display the the package information. If you want to see the package information then you can use the following command:

sudo apt show vlc
EXPLANATION
  • show: Provides all the information about a given package.

Showing the package details with apt

You can see all the information from the image of the vlc package.

Handle a Repository Using APT Package Manager

Handling a repository with apt means adding and removing a repository. Below you can see how to add and remove repository a repository.

A. Add a Repository in Ubuntu

If you want to add a repository with apt you have to follow two steps.

Firstly you have to add the repository GPG key. The GPG key verifies the authenticity of the packages. To add the key you can copy this command on Ubuntu:

wget -qO - https://deb.opera.com/archive.key | sudo apt-key add -
EXPLANATION
  • wget: Command line utility that provides non-interactive and recursive downloading facilities.
  • -qO: -q means quiet a mode with standard output.
  • https://deb.opera.com/archive.key: The URL to which repository I want to add.
  • apt-key: MAnage the apt-key.
  • add: Add the GPG key.

Added key with apt

From the image, you can see it displays ‘OK’, which means the key has been added. You can add any repository according to your preference.

Secondly, once the key has been added, then you can install and add the repository. To add the repository you can copy this command:

sudo add-apt-repository ‘https://deb.opera.com/archive.key’
EXPLANATION

Adding new repository with apt

So, by this method, you can add a repository to your directory.

B. Remove a Repository With APT

To remove a repository from the directory you have to use the remove option with the add command. You can copy this command:

sudo add-apt-repository --remove ‘https://deb.opera.com/archive.key’
EXPLANATION
  • – -remove: Remove the added repository.

Remove repository with apt

Here I remove this repository which I added previously. So you can remove it according to your liking.

Getting Help to Use APT on Ubuntu

To see the description of all packages you can use the help option. You can copy the following command on Ubuntu:

sudo apt help
EXPLANATION
  • help: Displays the description of all commands, and options.

Get the help to use apt

Clean Old Repository Using APT Package Manager

If you want to remove all the unused old repositories then you can use the following command:

sudo apt autoclean
EXPLANATION
  • autoclean: Remove all the unused local repositories cache.

remove unnecessary repositories with apt

List All Dependencies of a Package

To list all the dependencies that a package depends on, you can copy the following command:

sudo apt depends vlc
EXPLANATION
  • depends: Show the dependencies on which a package depends.
  • vlc: Package that I want to see the dependencies.

List of all dependencies

From the image, you can see the list of dependencies of the vlc package.

Search for Broken Dependencies on Ubuntu

When you want to see the broken dependencies of a package then you can use the following command:

sudo apt-get check nano
EXPLANATION
  • apt-get: Provides a front-end command line interface for the package system.
  • check: Check a package with broken dependencies.
  • nano: The package I want to check.

check the broken dependencies with apt

As It has no broken dependencies it did not show any dependency error.

Locate the Installed Packages

If you want to know the list of the files and the location of installed packages then you can use the dpkg tool which is the backend of the apt package manager:

sudo dpkg -L apache2
EXPLANATION
  • dpkg: Debian-based low-level command line tool to manage the packages.
  • -L: Option to list the file and locations.
  • Apache2: The package I want to see the location.

Showing the specific package location with apt

How to Get the Source Code for Ubuntu Sofware Package With APT

If you want to get the package source code then you can use the source option. You can copy the following command:

sudo apt source firefox
EXPLANATION
  • source: Display the source code of a package.
  • firefox: The package from I want the source code.

Showing source code of firefox with apt

From the image, you can see that it shows an error So you have to edit the source.list file. To edit you can copy the command on Ubuntu:

sudo nano /etc/apt/sources.list
EXPLANATION
  • nano: Text editor that provides some advanced features to edit the files.
  • /etc/apt/sources.list: Source file.

After using this command the following file will be opened and you have to remove the comment from the deb-src.

Removing the commenting part

Once you edit the file press CTRL+O to save all the changes and then press CTRL+X to exit. After editing you have to use the apt update command.

Update after changing source list with apt

Now, you can use the following command to see the source code:

sudo apt source firefox

Source code for a package with apt package manager

Conclusion

In this article, I have tried to show the key components, usages, and examples of how to manage software with apt and hope this will be easier for beginners to learn about apt package manager. By practicing the examples I hope the user will be able to maintain the operating system efficiently.

People Also Ask

What does the APT package manager do in Linux?

APT, elaborated as Advanced Package Tool, is a command line-based package manager that simplifies the process of software package installation, updation, or even removal on Debian-based distributions, such as Ubuntu.  It works as a bridge between the end user and a vast repository of software packages.

Do package managers on Linux Ubuntu use only APT?

No. Apt is a package manager tool that mainly manages the software packages in Ubuntu and other Debian-based distros. As apt is a user-friendly tool it is preferable to use for the beginner. Other tools also exist such as synaptic, aptitude, etc that provide additional software package management methods.

What is the reason to use a package management tool?

There are several reasons to use the package management tool such as to download, and install software packages, keep track of the latest updates, and upgrades, compile software from the source, etc. It also allows the users to manage dependencies for a seamless use of software packages.

How to install packages using the APT package management tool?

To install a software package using the APT package management tool is very easy. Open the terminal and run the command sudo apt update to update the repository information. Then run the command sudo apt install <package_name> to install the specific package using the APT package manager. For example, running the command sudo apt install vim in the terminal installs the text editor “vim”.

How to install .deb packages using the APT package manager?

To install a .deb package using the APT package manager, open the terminal and type the command sudo apt deb followed by the file_name with the .deb extension. For instance, run the command sudo apt deb atom-amd64.deb to install Atom.

Is it possible to install multiple packages using the APT package manager?

Absolutely. To install multiple packages using the APT package manager, specify each package name separated by spaces after the sudo apt install command. For example, to install both the vlc and handbrake packages, run the command sudo apt install vlc handbrake.

What is a package manager in Linux?

A package manager is a software application to download, install, remove, and upgrade software packages. It can be a command line tool or a tool with a graphical interface. Package managers mainly simplify the management process and help to handle the system efficiently. It lists all the dependencies and metadata that help the user to prevent the missing of information.

Is it possible to upgrade all the packages except one package with APT?

Yes. To upgrade all packages excluding one package by holding that package, mark the package to hold by coping the command: sudo apt-mark hold vlc
Then you can upgrade the whole system with upgrade command: sudo apt upgrade
If you want to include the package you can use the unhold command: sudo apt-mark unhold vlc

Is apt-get different from apt?

No, these two are the Debian-based package management tools that provide similar kinds of functions but apt provides more functionality and is easier to use than apt-get.


Related Articles


<< Go Back to Package Manager Examples | Package Management in Linux | Learn Linux Basics

4/5 - (26 votes)
LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now
Afia Zahin Oishi

Assalamualaikum, I am Afia Zahin, completed my graduation in Biomedical Engineering from Bangladesh University of Engineering and Technology, currently working as a Linux Content Developer Executive at SOFTEKO. A high achieving professional with a strong work ethic and able to work in a team in order to consistently achieve my goal and build my skillset. Able to handle difficult problems with patience and swift decision-making. Read Full Bio

Leave a Comment