FUNDAMENTALS A Complete Guide for Beginners
Installing useful software is one of the most essential tasks in our daily computing life. For example, you may be assigned to prepare a document or want to watch a movie. So, you need to install a document writer or a media player. In Linux, every software is in the form of packages. But, installing a software package may depend on some other packages as a prerequisite. These packages are called dependencies. Dependencies must have to be installed before to ensure the successful installation of the original package.
Key Takeaways
- Getting a comprehensive idea about dependencies.
- Learning the commands to check package dependencies in different Linux distributions.
- Handling automatic dependency resolution when installing and uninstalling a package.
- Knowing about some common errors regarding dependencies and their solutions.
Requirements:
- System running on Ubuntu/RedHat/ArchLinux.
- Login credentials to the system to enable sudo privilege.
What are Linux Dependencies?
Regarding Linux, dependencies are some software packages that are prerequisites to run another package or program smoothly. Most of the software packages you use daily in Linux reuse functions from other packages. So, to ensure a successful and complete installation of your intended package, you need to install those additional packages. These packages are known as dependency packages. Technically, dependencies can be of many types that I will discuss now.
Types of Dependencies in Linux
1. Runtime Dependency: These are libraries, binaries, or other software components that a program relies on to run successfully after it’s been installed on a user’s system. This category can further be divided into the following:
2. Package Dependency: Packages themselves can have dependencies on other packages. This is common in package management systems like APT, where installing one package might trigger the installation of other packages it depends on.
3. Build Dependency: These are packages and tools required to build and compile software from its source code. Developers who compile software from source code need to manage these dependencies.
How to Check Package Dependencies?
Dependencies are the most crucial part to handle when installing a software package. That’s why, you may need to check the dependencies before installing a package. Every distribution in Linux has commands that you can use to check the dependencies of a package. Some of them are listed below:
Distribution | Command to Check Dependencies |
---|---|
Ubuntu | apt show <package-name> |
RHEL | yum deplist <package-name> |
Fedora | sudo dnf info <package-name> |
ArchLinux | pactree -r <package-name> |
OpenSUSE | sudo zypper info <package-name> |
Dependencies in Ubuntu
Package managers are used to handle installing, removing, and updating a package. And dependencies are mostly connected with those tasks. However, Ubuntu has two widely used package management tools called apt and dpkg. Let’s discuss their usage in dependency resolution.
Install Dependencies Automatically in Ubuntu
If you’re using Ubuntu and want to automatically handle dependencies when installing packages, apt is designed to handle dependencies automatically by default. That means, when you use apt to install a package, it will take care of downloading and installing the package as well as any dependencies required. You generally don’t need to worry about managing dependencies manually. The command for installing a package with its dependency by apt is:
sudo apt install <package-name>
DPKG to Install Dependencies
dpkg is a lower-level package management tool in Debian-based systems i.e. Ubuntu that directly installs, removes, or manages individual Debian package (.deb) files. dpkg does not automatically resolve dependencies. You would need to manage dependencies manually if you use dpkg directly. Command for installing a .deb file using dpkg is:
sudo dpkg -i <filename.deb>
When you try to install a .deb file, it will show the dependency list in the terminal. Then you have to manually download the dependency packages from a trusted source and install them with the above command before installing the intended package.
Dependencies in RedHat
yum and rpm are two package management tools available for RedHat-based Linux distributions. Here, yum is a high-level package management tool that can automatically handle dependencies while installing or updating a package but rpm can’t.
YUM to Install Package With Dependencies
Yum is by default degined to streamline the process by automatically managing dependencies for you. To install a package and its dependencies using yum, simply use the following command with the actual package name in the place of <package-name>:
sudo yum install <package-name>
Using RPM to Install Package
RPM is a low-level package manager in RedHat-based systems such as RHEL, Fedora, CentOS, etc. It doesn’t install dependencies automatically. The command for installing a package using rpm is:
sudo rpm -ivh <package.rpm>
Install RPM Package Without Dependencies
If the package you want to install using rpm has dependencies then the above command can’t install the package and shows the dependency list that is to resolve first. However, installing RPM packages without dependencies can lead to potential issues and an unstable system. Still, if you are sure that you want to install the package ignoring the dependencis, use this command for that purpose:
sudo rpm -ivh –nodeps <package.rpm>
Dependency Tree
The dependency tree refers to the hierarchical structure of dependencies that exist between software packages on a Linux distribution. In a dependency tree, packages are organized in a way that shows which packages depend on others to function properly. Here, dependencies can be either runtime dependencies, which are required for the software to run, or build dependencies, which are required to compile or build the software. For example, the dependency tree of VLC player looks like this:
APT Dependency Tree
The APT dependency tree is the hierarchical structure of dependencies that is previewed by APT. If you are using Ubuntu or any other Debian-based Linux distribution, you can use apt package manager tool to list hierarchical dependency structure of a package by the following command:
sudo apt-get install -y apt-rdpends
sudo apt-rdepends <package-name>
Reverse Dependencies
Reverse dependency means the backward dependencies of a package. Actually, it is opposite to forward dependencies. For example, if Package B is required by Package A, then Package A becomes a reverse dependency of Package B.You can use commands from the table below to see reverse dependencies of a package.
To View | Command |
---|---|
APT Reverse Dependency | sudo apt-rdepends -r <package-name> |
RPM Reverse Dependency | rpm -q –whatrequires <package-name> |
Pacman Reverse Dependency | pactree -r <package-name> |
Remove Package and Dependencies
Removal of a package is as necessary as installing it. Because unnecessary packages cost system memory. However, you may not be using an installed package because you don’t need it anymore. Besides, sometimes you may need to install a package for doing a one-time task. Linux provides the option to remove a package with or without its dependencies. You can use commands from the table below according to your need:
Distribution | Remove Only the Package | Remove Package With Dependencies |
---|---|---|
Ubuntu | sudo apt remove <package-name> | sudo apt autoremove <package-name> |
RHEL, CentOS, Fedora | sudo yum remove <package-name> | sudo yum erase <package-name> |
ArchLinux | sudo pacman -R <package-name> | sudo pacman -Rs <package-name |
Common Challenges That May Arise
Though some package managers automatically handle dependencies, the following errors occur most frequently when installing and updating a package:
A. Packages Have Unmet Dependencies
A common problem in installing a package is dependency unmet. Usually, some package managers such as APT (Advanced Package Tool) install dependencies before installing the intended package. But when you use lower-level package managers like DPKG to manually handle dependencies, an error message may appear like “the following packages have unmet dependencies”. This typically happens when a package you’re trying to install or update requires other packages to be present, but those required packages are either missing or not compatible with the current system configuration.
B. RPM Error Failed Dependencies
This is a dependency problem that is generally found in RedHat-based Linux distributions where RPM is the package manager. While installing or removing a .rpm file manually, you may get failed dependencies error. It happens because there may require a certain pre-requisite rpm to be installed before installing the main rpm. So, to solve this problem, you must install those pre-requisite packages before.
Conclusion
Modern package managers in Linux distributions, such as apt in Debian-based systems, yum in RedHat-based systems and pacman in ArchLinux, automatically handle dependencies when you install or update software packages. This automation simplifies the process of managing software and contributes to a smoother and more reliable computing experience. Moreover, you can manually resolve dependencies by low-level pacakge management tools such as dpkg in Debian and rpm in RedHat.
People Also Ask
Related Articles
- How To Check Package Dependencies in Linux [3 Easy Ways]
- How to Install Dependencies Using dpkg? [Easiest Solution]
- How to Install Missing Dependencies in Ubuntu? [4 Methods]
- Install Dependencies Automatically in Ubuntu [3 Exclusive Methods]
- 5 Methods to Remove Package and Dependencies in Ubuntu
- How to Install RPM Package With Dependencies? [3 Methods]
- 2 Ways to Install RPM Without Dependencies in Linux
- How to Check RPM Reverse Dependencies in Linux? [4 Methods]
- [Solved] RPM Failed Dependencies Error in RedHat
- 2 Methods to Install YUM Packages with Dependencies
- Remove Packages without Dependencies Using Yum [2 Methods]
- [Solved] The Following Packages Have Unmet Dependencies Error
- How to Check APT Dependency Tree in Linux? [4 Methods]
<< Go Back to Package Management in Linux | Learn Linux Basics