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.
What is APT Package Manager in Linux?
The package manager for handling the .deb packages is APT which uses the apt,apt-get tools to manage the operating system. As 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:
- Usage: Primarily used in Debian and Ubuntu, front end for low-level dpkg
- File extension: The file extension for the APT package manager is .deb.
- Tools: apt-get, apt, and other APT-related commands.
- Key Features: Dependency resolution, Easy automatic package management and upgrade repository handling, Invoke the dpkg backend.
- Dependency Handling: Resolving dependencies automatically and installing required packages.
Why Use the APT Package Manager?
There are some key features that 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 with apt.
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
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
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.
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
You can use -q option instead of -qq option. It will show the same output.
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
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
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
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
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 -
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’
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’
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
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
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
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
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
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
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
After using this command the following file will be opened and you have to remove the comment from the deb-src.
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.
Now, you can use the following command to see the source code:
sudo apt source firefox
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
- How to Use DNF Package Manager in Linux [A Complete Guide]
- How to Use Yum Package Manager in RHEL [A Total Guide]
- A Total Guide on RPM Package Manager in Linux
- The Synaptic Package Manager [A Complete Guide]
- Pacman Package Manager in Linux [How to Use It]