Day 7 : Understanding package manager and systemctl

What is a package manager in Linux?

A package manager in Linux is a tool that automates the process of installing, updating, configuring, and removing software packages on a Linux system. It keeps track of what software is installed on your computer, and allows you to easily install new software, upgrade software to newer versions, or remove software that you previously installed

What is a package?

A package is a compressed file archive that contains all the files needed to install and run a specific piece of software. This includes the actual program files, configuration files, scripts, and metadata, which describes the package and its dependencies.

Types of Packages:

  • Binary Packages: These contain precompiled executables and libraries, ready to be installed on a system without needing to be compiled from source. Example formats include .deb (Debian-based systems) and .rpm (Red Hat-based systems).

  • Source Packages: These include the source code of the software, which needs to be compiled before installation. This allows customization during the build process.

Example Package Formats:

  • DEB: Used in Debian-based distributions like Ubuntu. Managed with tools like dpkg and apt.

  • RPM: Used in Red Hat-based distributions like Fedora and CentOS. Managed with tools like rpm, yum, and dnf.

  • TAR.GZ/TAR.XZ: These are generic compressed archive formats often used for distributing source code.

Different kinds of package managers:

  • APT (Advanced Package Tool): Used in Debian-based distributions like Ubuntu. Command-line utility: apt-get or apt.

  • YUM (Yellowdog Updater, Modified): Used in Red Hat-based distributions like CentOS and Fedora. Replaced by dnf in newer versions.

  • DNF (Dandified YUM): An improved version of YUM, used in Fedora, Red Hat, and CentOS.

  • Zypper: Used in SUSE and openSUSE.

  • Pacman: Used in Arch Linux and its derivatives.

Example Commands:

  • APT:

    • sudo apt update - Updates the package list.

    • sudo apt install package_name - Installs a package.

    • sudo apt remove package_name - Removes a package.

  • YUM/DNF:

    • sudo yum install package_name - Installs a package using YUM.

    • sudo dnf install package_name - Installs a package using DNF.

  • Pacman:

    • sudo pacman -S package_name - Installs a package.

    • sudo pacman -R package_name - Removes a package.

Steps to Install Docker

  1. Ensure your system is up to date

    sudo yum update -y

  2. Install necessary packages for managing repositories

    sudo yum install -y yum-utils device-mapper-persistent-data lvm2

  3. Add Docker's official repository to your system

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

  4. Install the latest version of Docker

    sudo yum install -y docker-ce docker-ce-cli containerd.io

  5. Start the Docker service and enable it to start on boot

    sudo systemctl start docker

    sudo systemctl enable docker

  6. Check if Docker is installed correctly

    docker --version

Steps to Install Jenkins

  1. Ensure your system is up to date

    sudo yum update -y

  2. Install Java

    sudo yum install -y java-17-openjdk

    Note : Jenkins requires Java17 or Java21 to work

  3. Add the official Jenkins repository to your system

    sudo yum install -y wget

    wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo

    sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

  4. Install Jenkins

    sudo yum install -y jenkins

  5. Start the Jenkins service and enable it to start on boot

    sudo systemctl start jenkins

    sudo systemctl enable jenkins

    sudo systemctl status jenkins

Checking the status of docker installed in system

  1. stop the service jenkins and post before and after screenshots

systemctl vs service

systemctl is the modern, recommended tool for managing services on most current Linux distributions (especially those using systemd)

Common Use : Modern systems, RHEL 7+, CentOS 7+, Ubuntu 15.04+

service is an older tool used by systems with SysVinit or Upstart. While it still works on some systems, it’s being replaced by systemctl in newer systems

Common Use : Older systems (RHEL 6, Ubuntu 14.04)