How to install dependencies with apt?

As Linux users, we all have faced an error about missing “dependencies” while installing some piece of software at one point or another. In general, such errors or, more appropriately, messages are caused by a part of the program being unavailable, outdated, or missing. In this guide, we will be discussing how to address these problems correctly.

What are dependencies?

Dependencies are files or components in the form of software packages essential for a program to run properly. This is the case with Linux overall – all software depends on other pieces of code or software to function correctly. So, this sort of “sectional” approach is where dependencies originate from. They are additional but essential pieces of code that are crucial to making programs work. This also explains why we get dependency errors during program installations as the programs being installed depend on other, missing code.

What is APT?

In the domain of Linux and, more specifically, Ubuntu, APT is short for Advanced Package Tool. It is the primary user interface that comes equipped with libraries of programs pertinent to software package management in Linux distributions such as Ubuntu and Debian.

Then comes the apt command, which is the most common way of interfacing with the Advanced Package Tool. Ubuntu users use apt to install new software, update and upgrade not only existing packages but also the entire operating system. This is what makes apt a very powerful and commonly used command in Ubuntu. Furthermore, the abilities of the apt command are not limited to just installing software packages, as it also plays a very important role in handling dependencies.

When downloading dependencies, we use the apt-get command. The primary function of apt-get is to obtain software packages and information from their respective repositories. The sources of these packages are authenticated and secure. The same procedure works for updating and removing dependencies.

Installing dependencies

Now, let us finally get into using the apt-get command and start installing dependencies. But before that, it is important to learn what the syntax of this command is.

$ apt-get [options] command

The syntax described above is the most commonly used ones; however, there are some other ways to call this command.

$ apt-get [options] install |remove pkg1 [pkg2…]

Another method to use apt-get is as follows.

$ apt-get [options] source pkg1 [pkg2…]

With that being said, you should now have a good general understanding of how apt-get works and how you can use it to install dependencies. The next step is to start looking at practical instances of its usage to see how we can use different command variants to manipulate dependencies.

Let us suppose that you want to install Python on your Ubuntu system. The first thing you would need before you install Python is a dependency known as libpython2.7-minimal. So, you can run the command below to get it.

$ apt-get install libpython2.7-minimal

(You may need to enter Ubuntu as root, so run $ sudo -i)

The output shows that the required package has been retrieved, extracted, and configured. We also get the amount of storage space the package is consuming. If any missing packages are remaining, we can simply run the command below to install those as well.

$ apt-get install libpython2.7-minimal libpython-stdlib:amd64

Now that all the dependencies are taken care of, we can install Python with the traditional command as follows.

$ apt install python

That pretty much covers how you can install dependencies in Ubuntu; however, there are other ways you can manipulate them as well. We will cover these in the next section.

Additional Information

Let’s say, for instance, you wish to remove the dependency we just installed. You can do that by executing the following command.

$ apt-get remove libpython2.7-minimal

You can run an apt command to update all the packages on your system. This is generally considered good, precautionary practice before proceeding with regular processes. It makes sure that all of your dependencies are met and updated.

$ apt update

or

$ apt upgrade

Next, we will see how one can list all the packages on their system by running an apt command. The output of this command will display to us a long list of software packages that are available for installation.

$ apt-cache pkgnames

However, you may want to install a specific package but not know which other dependencies need to be installed for it to work. Ubuntu fixes this issue through the showpkg flag. Run the command below to find out which dependencies are required.

$ apt-cache showpkg libslang2

Here, libslang2 is the initial package we wanted to install. In short, we can use the showpkg command to obtain more information on the dependencies we need for a certain package.

As we mentioned earlier, all the packages we install consume disk space, whether additional dependencies or the main programs themselves. Therefore, due to excessive dependencies, our computer can get cluttered. But worry not, as Linux has us covered in that department as well. You can simply run the commands given below to “clean” your dependencies.

$ apt-get clean
$ apt-get autoclean

In CentOS, the same operation is performed by the commands yum clean or yum cleanall. The clean flag clears all .deb files from the repository in var/cache/except for lock files. However, the autoclean flag also clears all the .deb files from the repository as mentioned above, but only the ones that have gone obsolete. These software packages are not available for download anymore.

Conclusion

In this article, we went into great detail about how one can install dependencies through apt. We first learned how dependencies work and why they are needed. Later on, we saw how one could install them and further manipulate them through other commands.



from Linux Hint https://ift.tt/3r7pr50

Post a Comment

0 Comments