How to use APT to manage packages on Ubuntu?

One aspect that differentiates Linux from Windows and macOS is the way the programs are installed. As we have recently observed, there is the possibility of universal installation with Flatpak and Snap. However, these packages are not the majority in Linux and it is also not possible to install development libraries like this. So in Linux, the package managers are available. So, with this post, you will learn how to use APT to manage packages on Ubuntu.

One moment, what is APT?

If you are new to the world of Ubuntu, Debian, and Linux Mint, you probably do not know what APT is.

APT stands for Advanced Packaging Tool and is a package manager for Debian-based distributions. It stands out for its ease of use and for being created in C++ so it is fast and efficient.

With APT it is possible to manage packages in these distributions, that is to say, to install, to uninstall and to look for these same ones in the added repositories.

On the other hand, APT is one of the oldest package managers in existence. With a slow but rather solid development, APT is designed to manage Debian’s own DEB and derivative packages. However, it is also possible to use it on other systems of the Unix family thanks to its compatibility with them.

Likewise, APT is a tool intended to be used in the terminal as a command. This makes it even faster to use. However, not many users like using the terminal and so graphical interfaces like Synaptic have been created to help with the task.

However, If you use Ubuntu or Linux Mint then you have used APT. Maybe not in the terminal, but the application store, as well as the update managers of these distributions, work with APT.

Package manager?

Any Linux distribution is the result of the union of several software components. Of course, they all match in the same recipe. One of these ingredients is the Linux kernel, of course, but so is the package manager.

A package manager is a shell application that installs, uninstalls, and searches for packages within the system’s configured repositories. Over time, package managers have improved and added new features and are very powerful.

Installing packages on Linux is not always easy due to the dependencies that the package may have. Typically, an entire program, such as a VLC, is included in a package. The VLC package depends on other libraries that are also in the repositories. The main use of the package manager is that it will take care of these dependencies for us. Then, when you want to install VLC, the package manager will read the dependencies on it, look them up in the repositories, and install everything in one process. As you can see, this makes the installation process much easier.

On the other hand, the reverse is also true. You can uninstall a package along with its dependencies with APT.

Linux distributions every day try more and more to offer polished graphic interfaces that help the newcomer user. Nothing is faster and more effective than using APT in the terminal.

That is why we will explain how to use it. At least the basic and most used operations by the users, so you will have no problems using it on your system.

How to use APT to manage packages on Ubuntu?

As I mentioned, APT is used from the terminal. Since installing packages and programs is a delicate matter, it requires root permissions.

So open a terminal and let’s start playing.

Refresh the system repositories

System repositories are set up in a text file in /etc/apt/source.list. Over time these repositories will add new packages or update some. And for the system to get that new information, you often have to “sync” the system with the repository.

To do this, simply run the following command:

:~$ sudo apt update

Before installing or uninstalling packages, it is recommended to run this command first.

Installing a package using APT

To install a package using APT, just follow this basic syntax:

:~$ sudo apt install [package]

APT is very flexible and this means that in a single command, you can install several packages at once.

:~$ sudo apt install [package1] [package2] [...]

Once the dependencies are resolved, just accept the installation and it will start.

Uninstall packages

The subcommand that uninstalls packages is “remove”. So uninstalling packages is as simple as running

:~$ sudo apt remove [package]

As with the installation, you can uninstall several packages simultaneously.

:~$ sudo apt remove [package1] [package2] [...]

This way you can save a lot of time uninstalling packages or whole programs.

Manage packages on Ubuntu: upgrade all installed packages on Ubuntu

In Linux, the development of packages is quite active which causes many programs to be updated frequently.

On the other hand, the Linux development team also fixes bugs and vulnerabilities and sends them to the system as updates.

That is why all installed packages have to be updated as well. To do this you only need to use:

:~$ sudo apt upgrade

Remember to run this command after refreshing the repositories with:

:~$ sudo apt update

Making these updates is a basic operation to handle the packages in Ubuntu.

Searching for a package in the repositories

So far I have shown examples where you know the name of the package, but what if you do not? With APT it is also possible to search within the repositories for any package.

If you want to search for a package you have to use the following command:

:~$ sudo apt search [keyword]

Thus, only packages that start with or contain the keyword will be searched.

Knowing the information of a package

Thanks to APT you can show the complete information of a specific package:

~$ sudo apt show [package]

There you will have elementary information about the package such as version, source, priority and so on.

Show the dependencies of a package

A package in Linux has many dependencies and it is possible to know what they are with APT.

The command is as follows:

:~$ sudo apt depends [package]

This tool is very useful, as it allows us to know the dependencies of a package. This is for development purposes.

Download the source code of a package

Most of the programs in Linux are open source so it is possible to download the source code of these programs.

To do this, make sure that the source repository is enabled in the system’s sources.

:~$ sudo source [package]

This is interesting to examine codes and learn more about them.

Removing Files from Previously Installed Packages

When we install a package, first it has to be downloaded and once installed it remains on the system. Over time, this can be a problem because the memory capacity becomes full.

To delete these packages, run:

:~$ sudo apt clean

Remember this does not uninstall the packages from the system, it only removes the DEB downloaded with APT.

Show all packages that are installed on the system

To do this, simply run this command

:~$ sudo apt-cache pkgnames

This will result in a long list with the name of all the packages you have on the system.

Display the command help

These are the basic operations of the APT command. But that does not mean you can’t do more with the command.

That’s why there’s the command help from the terminal. With that information, you can further explore the operation of APT.

:~$ apt – help
Managing packages on Ubuntu with APT
Managing packages on Ubuntu with APT

As you see there you have another description of the command.

Conclusion

Installing programs on Linux is quite easy thanks to the new graphical interfaces for APT. However, knowing how it works on the terminal is quite useful to know about it especially on servers.

Of the package managers in Linux, APT stands out as being quite efficient and veteran. It may not be as modern as Pacman or DNF, but it more than fulfills its purpose.

Tell us, how much do you use APT? or do you prefer to go for the graphical interfaces?