Package Management in Linux

Learn via video courses
Topics Covered

Overview

Packages in Linux are similar to executable files in Windows operating system but are not executable. A package in Linux is a compressed software archive file containing all the files included with a software application that provides any functionality. Packages can be a command-line utility, GUI application, or software library. This process is the same as installing any application, software, or utility in Windows.

Introduction to Packages in Linux

Linux distributions use a package manager to install packages. Package management in Linux can be explained using the following; Package is a set of files, metadata, and other information required to install any software, application, or tools on a Linux. These packages are required to install, update, and upgrade these tools. These tools and software and the Linux distribution are upgraded through Package managers. Instructions on how to update and upgrade packages are covered further in the article.

Core Concepts for Package Management

Regarding package management in Linux, package management is the term used to signify the installation and maintenance of Packages in your system. Package managers reduce the requirement for manually downloading and installing various dependencies required for the software.

Packages

A package contains all the necessary data required for the installation and maintenance of the software package. These packages are created by someone known as a package maintainer. A package maintainer takes care of the packages. They ensure active maintenance, bug fixes if any, and the final compilation of the package.

Repositories

These Packages are present in the Repositories that contain packages specially designed, compiled, and maintained for each Linux version and distribution. These Repositories contain thousands of packages created by the distribution vendors. Sometimes projects may handle their packaging and distribution.

Dependencies

Some packages might require some other pre-installed software to function correctly. A resource or software that a package depends on is called its dependency. Dependencies include metadata on how to build the code you depend on and information on where to find the files containing it. The package manager takes care of all these problems for you. It will install, modify, upgrade, update, and remove package files and provide dependency resolution. Resolving a dependency means suppose you have software that requires Python version 3.1. You are trying to install another software that requires version 3.3, which causes a conflict, and this conflict will be required to resolve before proceeding with the installation of this software. The package manager facilitates this. The package manager also ensures we receive the original and authentic package by verifying their certificates and checksum to ensure they have not been modified.

What is a Package Manager in Linux?

In simple terms, a package manager is a software tool used for package management in Linux i.e. to manage the installation, removal, and updating of various software packages. It can be thought of as a hub for all software packages available for your system. The package manager keeps track of all the installed packages on the system, including their dependencies, and uses this information to resolve conflicts and handle updates.

Using a package manager in Linux can save us a lot of time and effort compared to manually installing software and its dependencies. When we install a package, the package manager automatically checks if any other software is required for it to work correctly and installs these dependencies for us. This relieves us from the problem of figuring out what other softwares are needed and manually installing them. A package manager can also automatically check for updates to installed packages and install them for us. This helps us to keep our system up-to-date and secure.

Functions of Package Manager

The Package managers can be of two types based on their functions. The first ones are low-level, which ensures installing a package, upgrading a package, or checking which all packages are installed. The other type is the high level which ensures dependency resolution.

Comparison between Various Package Managers and How to Use Them?

  • DPKG – This is the abbreviation for Debian-based Package Management System. All the Debian-based Linux and their distros use DPKG. DPKG is used with packages made for Debian-based Linux, which end with .deb Extension. Although it cannot download and install packages and their dependency automatically.

    • To install a package with DPKG, use the following command dpkg -i package_name.deb // This command will install the package with name package_name.deb
    • To remove a package with DPKG, use the following command dpkg -r package_name // This command will remove the package named package_name
  • APT - APT is the abbreviation for Advanced Packaging Tool. It is the most widely used tool and the default package manager available in Ubuntu and other Debian-based distros.

    • To install a package with apt, use the following command sudo apt install package_name // This command will install the package with the name package_name, change it according to the package name you wish to install

    • To remove a package with apt, use the following command sudo apt remove package_name // This command will remove the package with the name package_name. However, this doesn’t remove the dependencies and package configurations.

    • To completely remove the package with apt, use the following command sudo apt purge package_name // This command completely removes the package as well as the dependencies and configuration of the packages.

    • To remove any leftover dependencies, use the following command sudo apt autoremove // This will automatically remove any dependencies or leftovers from previously removed packages.

    • The apt update command: sudo apt update // This command gets a copy of the latest version of all the packages installed in our system from the repositories. Please note this does not upgrade any packages and only fetches the latest version of the package.

    • The apt upgrade command: sudo apt upgrade // This command will check the list of available upgrades and then upgrade the packages one by one. Usually, this command is run after “sudo apt update” so that initially, the list of all available updates is updated with the update command, and the upgrade is done with the Sudo upgrade command.

    • To upgrade one specific package as per the requirement sudo apt upgrade package_name // This command will only upgrade that specific package. However, you need to run the update command first to get an update, and then you can upgrade the package.

  • APT and APTGET

    • APT and APT–GET are very similar. You can consider apt as a modern and more human graphical interface-based implementation of the apt-get. Apt is more famously used than apt-get, but apt-get has its functionality, such as running low-level commands.
  • YUM- This is the abbreviation for “ Yellow Dog Updater, Modified ”. This was once known as YUP or Yellow Dog Updater. This package manager is primarily used in Red Hat Enterprise Linux. This package manager is a high-level package manager who can perform functions such as dependency resolution. As Yum Downloads and installs the package, it does not require any downloaded files.

    • To install a package with yum, use the following command yum install package_name // This command will install the package with the name package_name, and change it according to the package name you wish to install.

    • To remove a package with yum, use the following command yum remove package_name // This command will remove the package named package_name and resolve any dependencies

    • To update a package using yum, use the following command yum update package_name // This command will automatically resolve any dependencies and update the package to the latest stable version.

    • The update command: yum update // This command will automatically fetch and install all the updates available for your system.

  • DNF - This is the abbreviation for “ Dandified YUM, ”. This package manager is the successor to YUM. This version includes several improvements, such as improved performance and quicker dependency resolution.

  • RPM - This is the abbreviation for “ Red Hat Package Manager ”. This package manager is used in Red Hat-based Linux operating systems such as Fedora, CentOS, etc. RPM is used with packages made for Red Hat-based Linux, and these packages end with .rpm Extension. This package manager is a low-level package manager who can perform functions such as installation, upgrade, and removal of packages.RPM requires the package downloaded to install the package.

    • To install a package with RPM, use the following command rpm -i package_name.rpm // This command will install the package with name package_name.rpm

    • To upgrade a package with RPM, use the following command rpm -U package_name.rpm // This command will install the package with name package_name.rpm

    • To remove or erase a package with RPM, use the following command rpm -e package_name // This command will remove the package named package_name

  • Pacman – Lastly, we have a very famous package manager called Pacman abbreviation for "Package manager". This Package manager is used majorly in Arch Linux and Arch Linux-based distros. In addition to automatically obtaining and installing all required packages, Pacman is capable of resolving dependencies. Pacman simplifies the process of installation and maintenance of packages.

    • To install a package with pacman, use the following command pacman -S package_name // This command will install the package with name package_name

    • To upgrade a package with pacman, use the following command pacman -Syu // This command will update all the packages in the system. It synchronizes with the repository and updates all the system packages based on updates available.

    • To remove or erase a package with pacman, use the following command pacman -Rs package_name // This command will remove the package named package_name

What are the Various Packaging Formats in Linux?

Various vendors provide their package manager and package format. Some package managers do allow the usage of multiple packaging formats to be used. Some of the prevalent packaging formats include:

  • RPM packages (.rpm)

    • The .rpm package extension was designed and developed by the Red Hat Linux distribution and used in the Red Hat Package manager (RPM)
  • Debian packages (.deb)

    • The .deb package was designed and developed by the Debian Linux distribution. They are majorly used in Debian-based Linux and distros.
  • TAR archives (.tar)

    • The .tar format is short for Tape Archive. This is just for creating an archive or combination of multiple files and directories into one file. Tar archives do not compress the consisting files and directories.
  • TGZ archives (.tgz)

    • The .tgz format is Tar archives, except for the difference that files in tgz archives are compressed using the GNU Zip compression technique. The result is a compressed archive file and thus less in size.
  • GZip Archives (.gz)

    • The .gz archives are created after direct compression using the GZIP Utility.

Comparing Package Managers and Installers

Though the functionalities of package managers and installers may sound similar, there are certain differences between them. To understand these differences, let us go through a brief comparison between package managers and installers-

Package ManagersInstallers
DefinitionA package manager is a software tool used to manage software packages and their dependencies in a Linux distribution.An installer is a software tool used to install a specific piece of software on a Linux system.
FunctionPackage managers are used to install, update, and remove software packages, as well as manage dependencies and repositories.Installers are used to install a specific piece of software, usually with a graphical user interface (GUI) that guides the user through the installation process.
Source of PackagesPackage managers typically obtain packages from repositories maintained by the distribution or community, ensuring compatibility and security.Installers may obtain packages from various sources, such as the developer's website or a third-party repository, which may result in compatibility or security issues.
UpdatesPackage managers can update multiple packages at once, and can handle dependencies and conflicts automatically.Installers may require manual updates or may not support updates at all, which can lead to security vulnerabilities.
System IntegrationPackage managers integrate with the system's package database, ensuring consistency and compatibility with other software components.Installers may not integrate with the system's package database, which can result in conflicts or version mismatches with other software components.

Conclusion

  • Packages are compressed software archive files containing all the files included with a software application.
  • The basic functioning of Packages, Package management in Linux, and Package maintainers.
  • Usage of Repository and dependencies in Packages.
  • Various package managers and their usage. For eg. DKPG, APT, APT GET, YUM, DNF, RPM and Pacman
  • Various types of Packaging formats. For example, RPM, Debian, Tar, TGZ, and Gzip Archives.