03 - Linux Package Management

Introduction to Package Managers

  • One of the common ways to categorize Linux distribution is by the package manager it uses.

  • For example:

    • Distributions such as RHEL, Fedora and CentOS. are based on RPM. Hence they are known as RPM based distribution.

    • The Debian family including Ubuntu, Debian and Linux Mint e.t.c. make use of Debian based package managers such as the DPKG.

deb-rpm

What is a Package?

  • A package is a compressed achieve that contains all the files that are required by a particular software to run.

  • Example:

    • For Ubuntu System, we want to install a simple editing system such as gimp which stands for GNU Image Manipulation System.

    • To do this, we can make use of the gimp.deb package which contains all the software binaries and files needed to for the image editor to run along with the metadata which provides the information about the software itself.

  • There are hundreds of linux distributions available, and they run different sets of tools and libraries, software and possibly even different linux kernels, as a result of this a linux program may not run the same way from one system to another.

  • To fix this problem packages include a manifest of dependencies or list of programs in versions that must be satisfied for the package software to run correctly on a given computer.

  • Each of these dependent packages may have dependencies of their own which makes package installation management a very tedious process. This is where a Package Manager comes in.

Package Manager

  • A package manager is a software in a Linux system that provides the consistent and automated process in installing, upgrading, configuring and removing packages from the operating system.

Functions of Package Manager

  1. Package integrity and Authenticity

  2. Simplified Package Management

  3. Grouping Packages

  4. Manage Dependencies

Types of Package Managers

  • DPKG: Base package manager for Debian-based distributions.

  • APT: A newer frontend for the dpkg system found in Debian-based distributions such as Ubuntu.

  • APT-GET: Traditional frontend for the dpkg system found in Debian-based distributions.

  • RPM: Base package manager for Red Hat-based distributions.

  • YUM: A frontend for the RPM system found in Red Hat-based distributions.

  • DNF: A more feature-rich frontend for the RPM systems.


RPM and YUM

RPM (Redhat Package Manager)

  • This package manager is used in RHEL as well as other linux distributions.

  • The File extensions for packages manage by RPM is .rpm

Working with RPM

  • RPM has five basic modes of operations.

  • Each of these modes can be run using rpm command followed by a specific command options.

  • Despite of this, RPM doesn't resolve dependencies on its own. This is why we make use of a higher level of package manager called YUM.

    1. Installing:

       [~]$ rpm -ivh telnet.rpm          # i = install, v = verbose
      
    2. Uninstalling:

       [~]$ rpm -e telnet.rpm          # e = install
      
    3. Upgrade:

       [~]$ rpm -Uvh telnet.rpm          # U = upgrade
      
    4. Query:

       [~]$ rpm -q telnet.rpm     # q = query into the database (check the package version using this)
      
    5. Verifying:

       [~]$ rpm -Vf <path-to-file>          # V = verify
      

YUM (Yellowdog Updater Modifier)

  • RPM Based Distros: YUM is a free and opensource package managers that works on RPM based Linux systems.

  • Software Repositories: It works with software repositories which are essentially a collection of packages and provides package independency management on RPM based distro. The repository information is stored in /etc/yum.repos.d/ and repository files will have the .repo extension.

  • High Level Package Manager: It acts as a high level package manager but under the hood it still depeneds on RPM to manage packages on the linux systems.

  • Automatic Dependency Resolution: Unlike RPM, YUM handles package dependencies very well. It is able to install any dependencies packages to get the base package install on the linux system.

Installing the package using YUM

  • yum install: YUM first runs transaction check, if the package is not installed in the system, yum checks the configured repositories under /etc/yum.repos.d/ for the availability of the requested package.

  • It also checks if there are any dependent packages are already installed in the system or if it needs to be upgrade.

    yum-cmd

  • After this step, transaction summary is displayed on the screen for the user to review, if we wish to proceed with the install enter the y button (this step can be skipped by providing the -y flag with the yum install command).

  • Yum will download and install necessary RPMs to the system.

    yum-cmd1

  • If you want to update a single package, use yum update command. If the package is already in the latest version in the repository and hence no action will be taken.

    yum-update

Commands:

  • yum repolist: to list all the repos added to the system

      $ yum repolist
    
  • yum provide <package-name> : to check which package should be installed for specific command to work.

      $ yum provides scp
    
  • yum install <package-name> : to Install a package

      $ yum install httpd
    
  • yum install <package-name>: to Install a package. (-y = automatic approval)

      $ yum install httpd -y
    
  • yum remove <package-name>: to remove a package

      $ yum remove httpd
    
  • yum update <package-name>: to update a package

      $ yum update telnet
    
  • yum update <package-name>: to update all packages in the system (without any arguments).

      $ yum update
    

DPKG and APT

DPKG (Debian Package Manager)

  • This package manager is used in Debian-based systems.

  • The File extensions for packages manage by DPKG is .deb

Working with DPKG

  • Similar to RPM, DPKG can be used for the below.

    1. Installation / Upgrade:

       dpkg -i telnet.deb
      
    2. Uninstallation:

       dpkg -r telnet.deb
      
    3. List:

       dpkg -l telnet     # list packages installed in the system along with the version number and short description
      
    4. Status:

       dpkg -s telnet
      
    5. Verifying:

       dpkg -p <path-to-file>     # Displays details about the package eg. version number, maintainer, etc.
      

APT and APT-GET

  • Similar to RPM, DPKG doesnt resolve the dependencies when it comes to package management.

  • Install may fail due to dependencies issues. This is the reason why we use higher level debian package managers such as APT and APT-GET.

APT

  • APT stands for advanced package managers, it is more user friendly and overall better tool compared to APT-GET.

      $sudo apt install gimp
      $sudo apt-get install gimp
    
  • APT act as a frontend package manager that relies on DPKG utility.

  • In similar to YUM, APT relies on software repository that contains packages that would eventually be installed on a system.

  • The software repository for APT is defined in /etc/apt/sources.list file.

Commands

  • apt update: to refresh a repository.

      $ sudo apt update
    
  • apt upgrade: to install available upgrades of all packages currently installed on the system.

      $ sudo apt upgrade
    
  • apt edit-sources: Another way to update the repository. This opens up the /etc/apt/sources.list file in the text editor of your choice.

      $ sudo apt edit-sources
    
  • apt install <package-name>: to install the package.

      $ sudo apt install telnet
    
  • apt remove <package-name>: to remove the package.

      $ sudo apt remove telnet
    
  • apt search <package-name>: to search or look for a package in the repository.

      $ sudo apt search telnet
    
  • apt list: to list all the available packages.

      $ sudo apt list | grep telnet
    

APT vs APT-GET

  • APT is a more user friendly tool when compared to APT-GET

  • In all the latest debian based distros APT is already installed by default.

Why APT is better than APT-GET

  • Try to install firefox package using both APT and APT-GET:

    • APT provides a readable-info, we get just enough information and also a progress bar.

    • APT-GET is just effective and doesn't provide the output in user-friendly format.

      apt-vs-apt-get

  • Search a telent package:

    • With apt, all its options are located in one place and can search with apt search telnet command.

    • On the other hand, there is no search command with apt-get. Instead, we have to use another tool called apt-cache search telnet.

apt-cache throws in a lot of extra information in the search result, which may not be really useful for the end user.

apt-vs-apt-get1


Previous Topic: 02 - Linux Core Concepts