Package Management in Linux

Pragya SaraswatPragya Saraswat
3 min read

Managing software on Linux is all about handling packages—installing, upgrading, deleting, and configuring them. Different Linux distributions use different tools for package management:

  • Red Hat-based systems (like CentOS) use yum/dnf and RPM.

  • Debian-based systems (like Ubuntu, Kali Linux) use apt.

Key Concepts

  • Package: A bundle that contains a software program and everything it needs to run.

  • Repositories: Warehouses where packages are stored.

  • Package Manager: A tool that fetches, installs, and updates packages for you.

Red Hat-Based Systems

yum (Yellowdog Updater Modified)

yum is the main package management tool for Red Hat-based systems. It handles dependencies when installing, updating, or removing software packages.

Basic Commands:

  • Install a package:

      sudo yum install nginx
    
  • Remove a package:

      sudo yum remove nginx
    
  • Upgrade a package:

      sudo yum upgrade <package-name>
    
  • Update a package:

      sudo yum update <package-name>
    

Difference between update and upgrade:

  • Upgrade: Deletes old packages.

  • Update: Keeps old packages so you can roll back if needed.

Package Rollback:

  • See package history:

      sudo yum history
    
  • Undo or redo actions:

      sudo yum history undo <id>
      sudo yum history redo <id>
    

RPM (Redhat Package Manager)

RPM allows you to install, uninstall, and query individual software packages. However, it doesn't handle dependencies like yum does.

Basic Commands:

  • Install a package:

      sudo rpm -i <package-name>
    
  • Upgrade a package:

      sudo rpm -U <package-name>
    
  • Remove a package:

      sudo rpm -evh <package-name>
    
  • Query installed packages:

      sudo rpm -qa
    
  • Get package info:

      sudo rpm -qi <package-name>
    
  • Get config files info:

      sudo rpm -qc <package-name>
    

dnf (Dandified yum)

dnf is the newer version of yum, used in Red Hat/CentOS 8 and later.

Basic Commands:

  • List available packages:

      sudo dnf list available
    
  • List installed packages:

      sudo dnf list installed
    
  • Install a package:

      sudo dnf install <package-name>
    
  • Remove a package:

      sudo dnf remove <package-name>
    
  • Upgrade a package:

      sudo dnf upgrade <package-name>
    
  • Update a package:

      sudo dnf update <package-name>
    

Debian-Based Systems

apt (Advanced Packaging Tool)

apt is used for managing software on Debian-based systems like Ubuntu.

Key Concepts:

  • APT Package Index: A catalog of all available software packages.

  • Repositories: Servers on the internet that store software packages. These are listed in /etc/apt/sources.list and /etc/apt/sources.list.d.

Basic Commands:

  • Update the package index:

      sudo apt update
    
  • Install a package:

      sudo apt install <package-name>
    
  • Remove a package:

      sudo apt remove <package-name>
    
  • Remove dependencies:

      sudo apt autoremove
    

Summing It Up

  • Install a package:

      sudo yum install nginx
      sudo dnf install nginx
      sudo apt install <package-name>
    
  • Remove a package:

      sudo yum remove nginx
      sudo dnf remove nginx
      sudo apt remove <package-name>
    
  • Upgrade/Update a package:

      sudo yum upgrade <package-name>
      sudo yum update <package-name>
      sudo dnf upgrade <package-name>
      sudo dnf update <package-name>
      sudo apt upgrade <package-name>
      sudo apt update
    
  • Manage package history (for yum):

      sudo yum history
    
  • Query packages (for rpm):

      sudo rpm -qa
      sudo rpm -qi <package-name>
      sudo rpm -qc <package-name>
    

Conclusion

Understanding package management is essential for effectively maintaining and managing a Linux system. Whether you are using Red Hat-based distributions like CentOS or Debian-based distributions like Ubuntu, knowing how to install, update, and remove software packages is fundamental. By mastering these tools and commands, you can ensure your system remains up-to-date, secure, and tailored to your needs.

0
Subscribe to my newsletter

Read articles from Pragya Saraswat directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Pragya Saraswat
Pragya Saraswat