The Linux ecosystem operates on a distinct principle compared to Windows or macOS. While Windows applications are typically self-contained and include all necessary components within their installation packages, Linux applications follow a more modular approach. They are designed as small, purpose-built tools that can interact with each other by passing information back and forth. Consequently, when installing software on Linux, managing dependencies—other software components required for proper functioning—can become challenging without proper assistance.
Unlike Windows applications, Linux applications don't come bundled with all their dependencies, leading to what is colloquially termed as "dependency hell." This is exacerbated by the fact that some applications may require specific versions of other software components. The absence or mismatch of these dependencies can result in functionality issues or outright failures.
To address this complexity, Linux distributions employ package managers. These tools are responsible for organizing, installing, and updating software packages, along with their dependencies. By centralizing software distribution and management, package managers like apt, yum, or pacman streamline the installation process and ensure that software components are compatible with each other.
How do Linux Package Managers Work?
Though each Linux package manager works slightly differently, they all tend to have a common architecture.
Repositories
Linux Package manager use something called a repository. Repositories are like organized lists of apps and their necessary parts. These lists are maintained by Linux distributions. They help keep software organized, separating stable versions from newer or experimental ones, and making sure they work well with specific versions of Linux.
Usually, you get software from these official repositories. But you are not stuck with just those. You can also add other repositories to your package manager. For example, TheJat
, an blog app, might not be in the official list for Ubuntu. But TheJat
provides its own list that you can add to your package manager. This lets you easily install and update TheJat
, along with other software, using the same tool you can for everything else.
This system gives Linux users more options and flexibility in getting the software they want.
Updating Repositories
First, it's common practice to update repositories and applications before installing new applications through the Linux package manager in the Linux OS. We'll use Apt as an example of this going forward. We'll also explain a couple of the key differences between some of the Linux package managers, too. So, let's use Apt to update the package manager repositories and applications first.
sudo apt-get update
First, note that we used the sudo
command first. This elevates privileges for the Apt application. This way, Apt has Root privileges. This is needed since more often than not pieces of applications are installed in parts of the OS that require elevated privileges to interact with. Likewise, Apt will also set things like environment variables if an application requires that. This is true for other Linux package managers, too.
Next, we called the Apt application itself. Apt has a couple of variants but all work the same way. In this case, we could substitute Apt-get for simply Apt or Aptitude.
Finally, we use the Update flag. This tells Apt to update the repositories. To be clear, what happens here is that the Linux package manager keeps a local cache of the package manager's repository lists locally on the computer. The primary repositories, along with the applications in it, are stored on servers elsewhere.
- Updates Package Lists: The "apt-get update" part tells the package manager (apt) to update its list of available packages. These lists are stored locally on your system and contain information about the latest versions of packages available from the repositories you have configured.
- Downloads Information: When you run this command, your system connects to the repositories specified in the configuration files and checks for updates. It downloads information about the latest versions of packages and any new packages that have been added to the repositories since the last update.
- Ensures Accuracy: By updating this information regularly, you ensure that your system has the most up-to-date information about available packages. This helps prevent installation errors and ensures that you are installing the latest versions of software.
Updating Linux Applications
Now that we updated our repository lists, we should update applications. Though this isn't required, it is good practice. We'll do that using the following command:
sudo apt-get upgrade
It does the following things:
- Check for Updates:
- The command checks the configured repositories for newer versions of software packages currently installed on your system.
- Download Updates:
- If newer versions are available, the package manager downloads these updates from the repositories.
- Upgrade Installed Packages:
- Once downloaded, the package manager upgrades the installed packages to their latest versions.
- Dependency Management:
- It automatically manages dependencies, ensuring that any required additional packages are installed or updated along with the main package being upgraded.
- System Integrity:
- Regularly running "sudo apt-get upgrade" helps maintain the integrity of your system by keeping installed software up-to-date with the latest features, bug fixes, and security patches.
Installing Linux Applications
Finally, let's install an application. Let's say that we want to install the git. We will use the following command:
sudo apt-get install git
- Command Invocation:
- You initiate the installation process by typing the command sudo apt-get install followed by the name of the package you want to install.
- Package Lookup:
- The package manager, in this case, "apt-get," checks its list of available packages to find the one you specified.
- Repository Query:
- It searches the repositories configured on your system. These repositories are essentially online stores of software packages managed by your Linux distribution.
- Dependency Resolution:
- If the package depends on other software components to function properly (dependencies), the package manager identifies and resolves these dependencies. It ensures that all necessary components are installed alongside the main package.
- Download and Installation:
- Once the package and its dependencies are determined, the package manager proceeds to download them from the repository servers onto your local system. It then installs them in the appropriate locations.
- Configuration:
- After installation, the package manager may perform configuration tasks specific to the installed package. This could involve setting up configuration files, creating directories, or performing other necessary setup tasks.
- Completion and Feedback:
- Once the installation process is complete, the package manager provides feedback indicating whether the installation was successful or if any errors occurred during the process.
There's a big difference in how some package managers handle applications
- Pre-compiled Binaries (APT, Yum):
- Package managers like Apt (used in Debian-based distributions) or Yum (used in Red Hat-based distributions) primarily deal with pre-compiled binaries. These binaries are specific to the distribution, version, and processor architecture of the system. They provide generic application builds that are compatible with a wide range of systems sharing the same architecture.
- Source Code Compilation (Pacman, Portage):
- In contrast, package managers like Pacman (used in Arch Linux) or Portage (used in Gentoo) download the source code for an application instead of pre-built binaries. They then compile this source code into executable binaries, tailored to the specific build environment of the user's system. This approach is aligned with the highly configurable nature of distributions like Gentoo and Arch, allowing users to optimize their system's performance and compatibility by compiling applications for their specific hardware.
- Configuration and Tuning:
- Distributions like Gentoo and Arch emphasize customization and system optimization. By compiling applications from source, users have greater control over the compilation flags, optimization settings, and dependencies, enabling them to tailor their system to their exact requirements and hardware specifications.
- Resource Efficiency:
- While compiling applications from source can be more resource-intensive and time-consuming compared to installing pre-compiled binaries, it offers potential benefits in terms of system performance, efficiency, and compatibility, particularly on systems with specialized hardware configurations or performance requirements.