Linux install dependency packages

How to Install and Correct Dependencies Issues in Ubuntu

A dependency is defined as a file, component, or software package that a program needs to work correctly. Almost every software package we install depends on another piece of code or software to work as expected. Because the overall theme of Linux has always been to have a program do one specific thing, and do it well, many software titles utilize other pieces of software to run correctly.

Introduction

Let’s review what dependencies are and why they are required. We all have, at one point or another, most certainly seen a message from our system when we were installing software regarding “missing dependencies.” This error denotes that a required part of the software package is outdated, unavailable or missing. Let’s review how to address those issues when we come across them on Ubuntu.

Install Dependencies

Ubuntu uses apt (or the Advanced Package Tool) for software package management. Most of the time, you will see the apt-get command used whenever you see the installation of something on Ubuntu. The main task of apt-get is to retrieve the information and packages from a repository with secure, authenticated software sources used to installation, upgrade, and/or removal of packages along with their dependencies.

This is the syntax of apt-get:

root@host:~# apt-get [options] command
root@host:~# apt-get [options] install|remove pkg1 [pkg2 . ]
root@host:~# apt-get [options] source pkg1 [pkg2 . ]

Now that we know what apt-get is and how the syntax for it should look like, let’s go through some of the most used apt-get commands, and we will explain how each of them manipulates dependencies.

Install Software

So let’s say that we want to install Python on our server. First, we would need to install a libpython2.7-minimal package/dependency. We can run this command to accomplish this.

root@host:~# apt-get install libpython2.7-minimal

We will get an output that the package itself has been found, unpacked and configured. Along with the info about disk space that package will take. If we are missing two dependencies, then we can just run a command like this to install those packages.

root@host:~# root@host:~# apt-get install libpython2.7-minimal libpython-stdlib:amd64

Now we can install python with pretty much the same command:

root@host:~# apt-get install python

Removal Software

If we want to remove this dependency, we can run the following command.

root@host:~# apt-get remove libpython2.7-minimal

This will remove libpython2.7-minimal package as well as all the associated dependencies it has.

Читайте также:  Удалить часть строки линукс

Update Software

If at any point you want to update all the system packages on the server, we can simply run this command. This command updates all of our software including any dependencies.

The second command will list all software packages it wants to install/update and will prompt us with a yes or no option before proceeding with the installation. Using this command, we ensure all of our dependencies are met.

List Software

If you want to list all available packages, we can use this command.

root@host:~# apt-cache pkgnames

We mention this command as it leads us into our next section specifically regarding dependencies. This command will show us a huge list of packages available for installation. Now, let’s say that we want to install the libslang2 package, but are unsure which dependencies need to be installed along with this package and which ones are not. We may not even know which ones we need. Luckily, Linux provides for this option by using the showpkg flag. We can run this command to see what dependencies are needed.

root@host:~# apt-cache showpkg libslang2

So, if we are not sure which dependencies we need, we can simply run the showpkg subcommand to get the information that we need.

Clean Dependencies

If you want to clear up some of the clutter that can sometimes take up our valuable disk space, we can use the following command to free up additional disk space.

root@host:~# apt-get clean root@host:~# apt-get autoclean

These commands will get the job done for us in the same manner that the yum clean and yum cleanall commands do on CentOS.

The clean flag removes all the .deb files from the local repository in /var/cache except the lock files.

The autoclean flag also removes all the .deb files from the local repository, but unlike the clean flag, it removes only the obsolete packages that can no longer be downloaded.

Unmet Dependencies Errors

Almost every Ubuntu user has seen the error «The following packages have unmet dependencies issues«. In this circumstance, the failure almost always is related to the apt package manager as opposed to the software being installed. Luckily, there are multiple options available to rectify this situation. We will look at several ways to address this issue.

Backup Configuration Files

First, as with any system modification, taking a backup of our configurations is a must. We do this to ensure that is any additional issues crop up, we can revert the changes we have made to restore our system files.

root@host:~# cp /etc/apt/sources.list /etc/apt/sources.list.bak root@host:~# cp /var/lib/dpkg/status /var/lib/dpkg/status.bak

Options

When these dependency errors occur, we have multiple options we can try to address the issue.

  • Enable all repositories
  • Update the software
  • Upgrade the software
  • Clean the package dependencies
  • Clean cached packages
  • Remove «on-hold» or «held» packages
  • Use the -f flag with the install subcommand
  • Use the build-dep command
  • Test install package
  • Reinstall the software
  • Remove the PPA
Читайте также:  Alt linux мой офис

List Packages Using Apt-mark

As an aside, when the apt-mark showauto command is used, it prints a list of each package that will be automatically added on a new line. If a package name is given, only those packages that will be installed automatically will be shown. We mention this, so we can note the packages that should be installed with the software.

root@host:~# apt-mark showauto softwarename

Option 1: Enable all Ubuntu Repositories.

Utilizing this option will allow for a wider base of software and dependencies to pull from. Then, once this is updated, we can try to reinstall the software.

root@host:~# add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe restricted multiverse" root@host:~# apt-get update

Option 2: Update the Software

Once the above command has finished, we can try to update the package again. Trying to update the software should be our first line of defense.

root@host:~# apt-get update softwarename

Option 3: Upgrade the Software

Next, we can show the packages that need to be upgraded and then attempt to upgrade the software.

root@host:~# apt-get -u && apt-get upgrade

Option 4: Clean the Package Dependencies

A corrupted package database or packages that were broken or not installed properly can cause this problem. This option uses the autoremove flag to address this.

root@host:~# apt-get autoremove

This command will remove only obsolete or unnecessary packages that no longer exist in the repositories.

Option 5: Clean Cached Packages

This command will clean up the local repository of downloaded packages. Then, try to reinstall the software.

Option 6: Remove «On-hold» or «held» Packages

To locate software that is held or on hold, we can use the apt-mark command. Once we have that info, we can use the remove and dry-run flags to see exactly what will be removed. Then, try to reinstall the software.

root@host:~# apt-mark showhold root@host:~# apt-get remove –dry-run softwarename

Option 7: Use the -f Flag

According to the apt-get man page, using the -f (or —fix-broken) parameter will allow the apt-get command to try to correct the broken dependencies issue. Do not use the package name in the command when using -f.

-f, —fix-broken
Fix; attempt to correct a system with broken dependencies in place. This option, when used with install/remove, can omit any packages to permit APT to deduce a likely solution. If packages are specified, these have to completely correct the problem.
The option is sometimes necessary when running APT for the first time; APT itself does not allow broken package dependencies to exist on a system. It is possible that a system’s dependency structure can be so corrupt as to require manual intervention (which usually means using dselect(1) or dpkg —remove to eliminate some of the offending packages).
Use of this option together with -m may produce an error in some situations. Configuration Item: APT::Get::Fix-Broken.

https://ss64.com/bash/apt-get.html

root@host:~# apt-get install -f root@host:~# dpkg --configure -a 0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded. root@host:~#

If you see the 0 upgraded message, this means this command has failed. We are not done yet, though. Let’s try to issue the command again.

root@host:~# apt-get install -f

Option 8: Use the Build-dep Command

Using this subcommand, we can install all the dependencies for ‘softwarename’. Then, we can try to reinstall the software dependencies individually.

root@host:~# apt-get build-dep packagename

Option 9: Test Install Package

The —dry-run flag shows us what apt-get would install without actually installing the package. This is useful with the above command. It can also sometimes show the dependency error prior to the software installation.

root@host:~# apt-get install --dry-run softwarename

Option 10: Reinstall the Software

There are certain dependency issues and conflicts which arise that apt cannot solve. When this occurs, apt will save those packages in an ‘on-hold’ state. This means they will not have been completely installed. Removing those software packages may fix the problem and might assist in solving the original issue. The apt-get purge command will remove the program, all the associated configuration files, and any plugins or settings from our system.

root@host:~# apt-get -u dist-upgrade root@host:~# apt-get --reinstall softwarename

If the output shows any packages in an “on-hold” state, we can go ahead and try to remove them. Once that command completes, run this command to

root@host:~# apt-get -o Debug::pkgProblemResolver=yes dist-upgrade 0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.

Now remove the held packages one at a time by executing dist-upgrade each time, until there are no more held packages. Afterwards, try to re-install your package. Make sure to implement the –dry-run option, in order to stay informed of the consequences:

root@host:~# apt-get remove -dry-run package-name root@host:~# apt-get remove package-name root@host:~# apt-get install package-name

Option 11: Remove Old PPA

The following commands remove the package, the PPA and the associated dependencies.

root@host:~# apt-get autoremove -purge PACKAGENAME root@host:~# apt-get install ppa-purge root@host:~# add-apt-repository -remove ppa:someppa/ppa root@host:~# apt-get autoclean

In the end, we can draw a conclusion that apt-get manages dependencies the same way that yum does. We can install dependency with the install subcommand, we can remove it with remove subcommand, update it with upgrade subcommand, and so on.

Читайте также:  Linux ubuntu virtualbox mac

If you are using Ubuntu and looking for the best way to manage your dependencies and packages, apt-get is a way to go. It’s superior to dpkg, and it’s more user-friendly.

If you continue to have issues with this, give us a call at 800.580.4985, or open a chat or ticket with us to speak with one of our knowledgeable, experienced Linux administrators today!

About the Author: Dean Conally

I am a Linux enthusiast and console gamer, dog lover, and amateur photographer. I’ve been working at Liquid Web for a bit less than two years. Always looking for knowledge to expand my expertise, thus tackling new technologies and solutions one day at a time.

Refer a Friend

Join our mailing list to receive news, tips, strategies, and inspiration you need to grow your business

Источник

Оцените статью
Adblock
detector