Ubuntu

How to Use APT Package Manager in Ubuntu 22.04

Ubuntu is a Debian-based Linux distribution that contains thousands of packages for different purposes and  to manage all these packages, we need some management tools, and the APT package manager is the tool to manage these packages on Ubuntu.

In this write-up, we will discover about the APT package manager and its usage to manage the packages on Ubuntu 22.04.

What is the APT package manager

The APT (Advanced Packaging Tool) package manager is used to install, update, upgrade, uninstall, and configure different packages which are present in the default repository of Ubuntu. There are around 60000 packages that come in the default repository, and these packages have some dependencies, so the APT package manager also helps to install those dependencies automatically along with the installation of the specific packages.

How to use the APT package manager to update packages

There are some bugs or improvements needed on which the development team of the concerned package is working so we can update all the packages to get the latest updates, and for this, we will use the command:

$ sudo apt update

In the above output, we can see that 27 packages can be upgraded.

How to upgrade the packages using the APT package manager

We have seen in the above output that 27 packages can be upgraded. To list down the packages which can be upgraded, we will use the command:

$ sudo apt list --upgradable

To upgrade all these packages, we will run the upgrade command using the APT package manager and also use the “-y” flag, so it will not ask for the confirmation and just upgrade all the packages:

$ sudo apt upgrade -y

Now, all the packages are upgraded, but if you want to upgrade any specific package instead of all the packages then you have to run the command with “–only-upgrade” and the syntax of the command will be:

$ sudo apt --only-upgrade [package-name]

Replace the package name with the concerned package you want to upgrade, for example, we want to upgrade the nano text editor so we will use the command:

$ sudo apt install --only-upgrade nano

The package has already been included in the newest version.

How to use the APT command to list down the packages

We can list down all the packages available on the Ubuntu operating system:

$ sudo apt list

If we  want to list down only installed packages, then we will use the command:

$ sudo apt list --installed

How to search the package using the APT package manager

We can also find out whether the package we want to install is available in the repository of Ubuntu by using the apt package manager. For example, we want to install a package of vim text editor, so we will search in the repository using the command:

$ sudo apt search vim

How to display the details of the packages using the APT package manager

We can also display the details of the package including its version, dependencies, and installed size by using the APT package manager, for example, we have displayed the details of the vim text editor:

$ sudo apt show vim

How to install a  package using the APT package manager

We can install the packages available in the default repository of Ubuntu using the APT package manager, for example, we will install the vim package using the command:

$ sudo apt install vim -y

How to remove a package using the APT package manager

We can also use the APT package manager to remove the installed packages from Ubuntu, for example, we will remove the installed vim package by using the command:

$ sudo apt remove vim -y

The above command will not remove the configuration files of the Vim package so we will use the purge command to remove them:

$ sudo apt purge vim -y

How to add the repository in Ubuntu using the APT package manager

To add the repository, for example, the PPA repository of any package we can use the “add-apt-repository”  command. To understand this, we will add the PPA repository of blender using the command:

$ sudo add-apt-repository ppa:thomas-schiex/blender

Similarly, we can remove the added PPA repository by using the “–remove” option with the command, for understanding, we will remove the above added PPA repository:

$ sudo add-apt-repository --remove ppa:thomas-schiex/blender

Conclusion

The APT package manager is a Linux tool that is used to manage the packages of the Linux operating system by installing, updating, configuring, and removing the packages. In this write-up, we have managed the packages Ubuntu by installing, removing, and updating them using the APT package manager.

About the author

Hammad Zahid

I'm an Engineering graduate and my passion for IT has brought me to Linux. Now here I'm learning and sharing my knowledge with the world.