Computer scienceSystem administration and DevOpsCommand linePackage managers

Package manager APT

5 minutes read

Introduction

Surely from time to time you need to install some new programs on your computer and update the ones that you already have. In GNU/Linux systems programs are stored in form of packages in special places — software repositories. If you use Debian or another Debian-based distribution, say Ubuntu (or its derivative), you can manage them through the package manager APT, which stands for Advanced Packaging Tool. Let's study the most useful and common commands of this manager in this topic.

Installing and removing programs

There are several tools in the APT, but we suggest you start with the apt command. It combines the most commonly used apt-get and apt-cache command options and is easier to type and remember.

Let's learn how to install a program. After apt simply type the install command, and then the actual name of the package you'd like to install:

apt install <package-name>

For example, installing spreadsheet application Gnumeric will look like this:

apt install gnumeric

After running this command, the system might request your password. Also, apt will usually ask you to confirm your actions. After that, apt will download and install your package.

Someday you might find you don't need some of the packages anymore or that you have installed the wrong stuff. Removing packages is as simple as installing them. Take a look at this command:

apt remove <package-name>

If you aren't entirely satisfied removing the package only, you can remove both package and configuration files by using this command:

apt purge <package-name>

Updating programs

You might wonder why bother updating our software in the first place? Well, because updates introduce new features and improvements, fix bugs and security flaws. Fortunately, there are only two commands you need to know to keep your programs up-to-date.

Firstly, check for the updates and then install them:

apt update  # update information
apt upgrade # install packages

These commands will update all currently installed packages on your system from the available repositories.

Remember, apt update downloads only the information about the versions of packages. It updates package source lists from repositories located in the file /etc/apt/sources.list and in the directory /etc/apt/sources.list.d. apt upgrade installs updates of packages using these files. If you do not update information in those files, apt won't know that there are updates available.

However, what if you want to update only some specific package or packages? In that case, just change the command apt upgrade to apt install in the example above. For instance, updating the previously mentioned package gnumeric will look like this:

apt update
apt install gnumeric

Obviously, it will do the trick if you've already installed the package. If you don't have it, then the command will install the package.

Searching for packages

Now you know how to work with packages, but how will you find the specific ones that you need? Simple! You can search for a specific package in the repositories. The command looks just like this:

apt search <package-name>

If a package name is too long or you don't know the whole name, you can use only part of the name. The search will work the same way.

Let's try to find a package using the word "bash":

apt search bash

As a result, you'll see a few packages:

android-androresolvd/bionic 1.3-1build1 amd64
  Daemon to transfer Android DNS property to resolv.conf

bash-builtins/bionic-updates 4.4.18-2ubuntu1.2 amd64
  Bash loadable builtins - headers & examples

biabam/bionic,bionic 0.9.7-7ubuntu1 all
  bash attachment mailer
...

In case you need the information about the package, this is the command line that'll help you:

apt show <package-name>

The output of this command will show you the description of the package, its dependencies, installation and download size, repositories that store this package, and other details.

Searching for files

Let's explore one more tool. Imagine you need to determine what package has installed a specific file. Or while installing a package you receive a message saying that "a particular library file cannot be located". Another tool, apt-file, will come in handy. It will quickly find out what package you can install to get that file. apt-file may not be installed on your system, so you should install it first (you already know how to do that). After the installation, use this command:

apt-file update

It will generate a database for it.

Now, try to find out what package has installed the file "bash" in the directory /bin. Like we did with apt search, type the location or the name of the file after the apt-file search command, but first, make sure that you've updated the database:

apt-file update
apt-file search /bin/bash

Conclusion

Let's sum up what we have learned. We hope that now you understand how to install and remove programs, how and why to update your packages, how to search for the program you need, and how to get the information about any package. That's definitely not everything that apt and other tools are capable of. However, mastering those few commands will give you the ability to do these important and common operations on your own system.

79 learners liked this piece of theory. 0 didn't like it. What about you?
Report a typo