Last modified: July 30, 2024

This article is written in: πŸ‡ΊπŸ‡Έ

Package Managers

Debian and Ubuntu are popular Linux distributions for home users. These distributions and their derivatives use the Advanced Package Tool (APT). Other distributions use alternative package managers, like DNF, YUM, Pacman, which have unique functionalities and syntax.

Be cautious with package managers as they install software and dependencies and may affect your system's configuration.

User
  |
  | uses
  V
Package Manager (e.g., APT, DNF, YUM, Pacman)
  |
  | fetches metadata and package lists from
  V
Package Repository
  |
  | downloads
  V
Package files (.deb, .rpm, .tar.xz, etc.)
  |
  | unpacks/installs to
  V
System directories (/usr/bin, /usr/lib, etc.)

Installing and Updating Software Packages

APT

APT (Advanced Package Tool) is the command-line tool used in Debian-based Linux distributions for handling packages. It's preferred over its predecessors, apt-get and aptitude.

I. Updating Repository Information

Before installing or upgrading packages, update the list of available packages and their versions:

apt update

II. Upgrading Installed Packages

To upgrade all installed packages to their latest available versions:

apt upgrade

III. Installing New Packages

To install a new package from the repositories. For example, installing httpd:

apt install httpd

IV. Installing Local .deb Files

If you have a .deb package file downloaded locally, install it using:

apt install /path/to/package/name.deb

V. Verifying Installation

To check if a package is successfully installed and to view its details:

apt show httpd

YUM

YUM (Yellowdog Updater, Modified) is a package manager used in Red Hat-based Linux distributions. It differs from apt in that it doesn't require repository updates before installing or updating software.

I. Checking for Updates

To check available updates for installed packages:

yum check-update

II. Updating All Packages

To update all packages to their latest versions:

yum update

III. Updating Specific Packages

To update a particular package, such as httpd:

yum update httpd

IV. Searching for Packages

To search for a package by name. For example, searching for apache:

yum search apache

V. Installing Packages

To install a specific package, like httpd:

yum install httpd

VI. Displaying Package Information

To display detailed information about a package:

yum info httpd

VII. Listing Installed Packages

To display a list of all installed packages:

yum list installed

VIII. Removing Packages

To remove an installed package, such as httpd:

yum remove httpd

IX. Cleaning Cache

To clean the YUM cache, which includes removing downloaded packages and metadata:

yum clean all

Tarballs

Installing software from tarballs is an alternative to using package managers on Linux. This manual method is broken down into three primary steps:

I. Extract

First, navigate to the directory containing the tarball. Use the following command to extract its contents:

tar -zxvf path_to_tar.tar.gz
cd path_to_tar

II. Compile

The process might vary depending on the software, but generally, you would run:

make

If there is a configuration file (configure script) present, especially one listing dependencies, run it before executing make.

III. Install

Installation is often done through make install, which should place the executable in the correct directory:

make install

Alternatively, for some software, you may need to manually copy the compiled executable to a directory like /usr/local/bin.

πŸ”΄ Caution: Remember that software installed via tarballs does not benefit from automatic updates typically provided by package managers. This means manually tracking and updating software for security patches and new features.

RPM

RPM (Red Hat Package Manager) is a low-level package manager used in Red Hat-based Linux distributions. It allows direct management of software packages but requires a bit more manual intervention compared to higher-level tools like YUM.

I. Downloading RPM Packages

To download an RPM package from a website:

wget http://some_website/sample_file.rpm

II. Installing Packages with RPM

To install a downloaded RPM package:

rpm -ivh sample_file.rpm

i stands for install, v for verbose (showing detailed output), and h for hash (displaying progress as hash marks).

III. Listing All Installed Packages

To list all installed packages:

rpm -qa

IV. Listing a Specific Package

To check if a specific package, like nano, is installed:

rpm -qa nano

V. Displaying Package Documentation

To display documentation files of a specific package:

rpm -qd nano

VI. Removing Packages with RPM

To remove an installed package:

rpm -e nano

e stands for erase, which removes the package.

πŸ”΄ Note: While RPM provides a granular control over package management, it doesn't resolve dependencies automatically. It's important to ensure that dependencies are managed manually or through a higher-level tool like YUM or DNF.

Software Package Repositories

A software package repository in the context of Linux and other Unix-like operating systems is a centralized storage location containing various software packages. These repositories are essential components in the package management system, utilized by package managers to download and install software and updates.

Key Components of a Repository

Common Repository Labels

Managing APT Repositories

APT repositories are defined in /etc/apt/sources.list and in the /etc/apt/sources.list.d/ directory.

apt update
apt install software-properties-common

Example: Installing Wine

To demonstrate managing APT repositories, here's how you can install Wine on a Debian-based system:

I. Get and Install the Repository Key

Download and install the GPG key for the Wine repository:

wget -nc https://dl.winehq.org/wine-builds/winehq.key
gpg -o /etc/apt/trusted.gpg.d/winehq.key.gpg --dearmor winehq.key

II. Add the Wine Repository

Add the Wine repository to your system's sources:

add-apt-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ focal main'

III. Update the Package Database

Update APT's package database to recognize the new repository:

apt update

IV. Install Wine

Install the stable version of Wine with:

sudo apt install --install-recommends winehq-stable

V. Verify the Installation

Confirm that Wine is correctly installed:

wine --version

πŸ”΄ Note: It's important to ensure that repositories and their keys are obtained from trusted sources to avoid security risks. Incorrect or malicious repositories can compromise the system's integrity and security.

Managing YUM Repositories

The configuration files for YUM repositories are located in the /etc/yum.repos.d directory.

I. Display Repositories

To display a list of all enabled and available repositories, use:

yum repolist all

II. Add a New Repository

To add a new repository by specifying its URL, use the yum-config-manager tool:

yum-config-manager --add-repo=[URL]

III. Enable a Repository

If a repository is disabled and you want to enable it, use the following command. Replace [repo_id] with the actual repository ID:

yum-config-manager --enable [repo_id]

IV. Disable a Repository

To disable a repository temporarily (for example, to prevent updates from that repository), use:

yum-config-manager --disable [repo_id]

Challenges

  1. Configure a Linux system to use both official and third-party repositories while preventing package conflicts.
  2. Safely upgrade a major software package (like Python or MySQL) ensuring all system dependencies are maintained.
  3. Script a solution to automatically switch to a backup repository when the primary YUM or APT repository fails.
  4. Create a script or use existing tools to automate security updates on a Linux system without breaking package dependencies.
  5. Download and compile a piece of software from a tarball, resolving all dependencies manually.
  6. Use the alien tool or similar to convert an RPM package to a DEB package and ensure it installs correctly on a Debian-based system.
  7. Manually resolve package dependencies for a complex software installation without using package manager automation.
  8. Set up and configure a custom YUM repository on a CentOS system.
  9. Install a Linux software package on a system without direct internet access using offline methods.
  10. Write a script to automate the cleanup of old or unused packages and maintenance tasks like cache clearing in a Linux environment.

Table of Contents

  1. Package Managers
  2. Installing and Updating Software Packages
    1. APT
    2. YUM
    3. Tarballs
    4. RPM
  3. Software Package Repositories
    1. Key Components of a Repository
    2. Common Repository Labels
    3. Managing APT Repositories
      1. Example: Installing Wine
    4. Managing YUM Repositories
  4. Challenges