๐Ÿš€Mastering Linux Package Management๐Ÿš€

#Day6ofDevOpsBlog

ยท

4 min read

๐Ÿš€Mastering Linux Package Management๐Ÿš€

๐Ÿ“ฆ What is a Package?

A package is a bundle of files and metadata. It is usually referred to as an application but it could be a GUI application, command line tool, or a software library (required by other software programs).Think of it as a neatly wrapped gift containing everything needed for a software application to run.

This can include:

  • Executable files: The main program that runs.

  • Libraries: Shared code that helps the program to function.

  • Documentation: Guides and manuals for using the software.

  • Configuration files: Settings that help the software run correctly.

๐Ÿ“ฆ Examples of Packages:

  • Application Software: Like a web browser or a game.

  • System Software: Like utilities for managing files or settings.

๐Ÿ“ฆ What is a Package Manager in Linux?

A Package Manager is like a superhero librarian for your computer. It is a tool which helps you to find, install, update, and remove software packages. Package managers ensure you always have the right version of software and all the necessary dependencies (other software the package needs to run).

  • APT (Advanced Package Tool): Used in Debian-based systems like Ubuntu.

  • YUM (Yellow-dog Updater Modified) and DNF: Used in Red Hat-based systems like CentOS and Fedora.

  • Pacman: Used in Arch Linux.

๐Ÿ› ๏ธ Different Types of Package Managers in Linux

๐Ÿง Debian-based Systems (e.g., Ubuntu)

  • APT (Advanced Package Tool): The most common package manager for Debian-based distributions.

      sudo apt update     # Update package list
      sudo apt install <package_name>  # Install a package-
    

๐ŸŽฉ Red Hat-based Systems (e.g., CentOS, Fedora)

  • YUM (Yellow-dog Updater Modified): Used in older Red Hat-based distributions.

      sudo yum update     # Update package list
      sudo yum install <package_name>  # Install a package
    
  • DNF (Dandified YUM): The next-generation / modified version of YUM.

      sudo dnf update     # Update package list
      sudo dnf install <package_name>  # Install a package
    

๐ŸŒ Arch Linux

  • Pacman: A package manager specifically for Arch Linux.

      sudo pacman -Syu    # Update package list and upgrade all packages
      sudo pacman -S <package_name>  # Install a package
    

๐Ÿ”ง What is systemctl and systemd?

โš™๏ธ systemd

systemd is a system and service manager for Linux, responsible for initializing the system and managing services and processes. It offers features like parallel service startup, on-demand activation of daemons, and managing system state.

๐Ÿ”„ systemctl

systemctl is the command-line interface used to interact with systemd and to examine and control the state of the โ€œsystemdโ€ system and service manager. With systemctl, you can:

  • Start and stop services.

  • Enable or disable services at boot.

  • Check the status of services.

๐Ÿ†š Differences between systemctl and systemd

  • systemd: The actual system and service manager.

  • systemctl: The tool to control and interact with systemd.

๐Ÿ“– Example Commands:

  • Start a service:

      sudo systemctl start <service_name>
    
  • Stop a service:

      sudo systemctl stop <service_name>
    
  • Check service status:

      sudo systemctl status <service_name>
    
  • Enable a service:

      sudo systemctl enable <service_name>
    
  • Disable a service:

      sudo systemctl disable <service_name>
    

๐Ÿณ Example: Installing Docker with Package Managers

Let's have a look at how to Install Docker using Package Managers.

๐Ÿง On Ubuntu

  1. Update your package list:

     sudo apt update
    
  2. Install required packages:

     sudo apt install apt-transport-https ca-certificates curl software-properties-common
    
  3. Add Docker's official GPG key:

     curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
    
  4. Set up the Docker repository:

     echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    
  5. Install Docker:

     sudo apt update
     sudo apt install docker-ce
    
  6. Verify the installation:

     sudo systemctl status docker
    

If the output of this command comes "Service is active / Service is running" means that we have successfully installed Docker.

๐ŸŽฉ On CentOS

  1. Update your package list:

     sudo yum update
    
  2. Install required packages:

     sudo yum install yum-utils device-mapper-persistent-data lvm2
    
  3. Set up the Docker repository:

     sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    
  4. Install Docker:

     sudo yum install docker-ce
    
  5. Start Docker:

     sudo systemctl start docker
    
  6. Verify the installation:

     sudo systemctl status docker
    

๐ŸŽ‰ Conclusion

Having a good knowledge of Package Managers is important in your DevOps journey because as a DevOps Engineer we are frequently required to install the required softwares and working with different Linux flavors, the knowledge of different types of Package Managers and their usage becomes important. I hope you enjoyed reading the article.

Feel free to explore more and enjoy your journey in the Linux world! ๐Ÿš€

ย