Day 7: Understanding package manager and systemctl in Linux

Day 7: Understanding package manager and systemctl in Linux

Introduction

In the intricate world of Linux administration, two fundamental concepts reign supreme: package managers and systemd. These tools play a pivotal role in managing software installations and system services, ensuring smooth operation and optimal performance of Linux systems. Let's dive deep into these concepts, exploring their intricacies and practical applications.

Understanding Package Managers

What is a Package Manager? A package manager is a software tool designed to streamline the installation, removal, upgrading, configuration, and management of software packages on a Linux operating system. It serves as a centralized hub for handling software-related tasks, offering users a convenient interface to interact with software packages.

What is a Package? A package refers to a bundle of software components, typically comprising the application binaries, configuration files, and metadata. These packages are stored in repositories and can be easily installed or removed using package managers. Whether it's a graphical application, command-line tool, or library, packages encapsulate software functionalities in a convenient format.

Types of Package Managers Package managers vary based on the packaging system employed by the Linux distribution. For instance, the RPM packaging system commonly used in Red Hat-based distributions like CentOS utilizes package managers such as Yum and DNF. On the other hand, Debian-based distributions like Ubuntu rely on package managers like apt-get and aptitude. Each package manager offers its unique set of commands and functionalities tailored to the underlying packaging system.

Installing Docker and Jenkins Using Package Managers

Now, let's put our knowledge into practice by installing Docker and Jenkins using package managers on Ubuntu and CentOS.

Installing Docker on Ubuntu:

  1. Update Package Lists: Before proceeding, ensure your system's package lists are up to date by executing:

      sudo apt-get update
    

  2. Install Docker: Once the package lists are updated, install Docker using the following command:

      sudo apt install docker.io
    

  3. Verify Installation: After installation completes, verify that Docker is running by executing:

      docker --version
    

Installing Docker on CentOS:

  1. Install Required Packages:

     sudo yum install -y yum-utils device-mapper-persistent-data lvm2
    
  2. Set up Docker Repository:

     sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    
  3. Install Docker CE (Community Edition):

     sudo yum install docker-ce
    
  4. Start and Enable Docker Service:

     sudo systemctl start docker
     sudo systemctl enable docker
    
  5. Verify Docker Installation:

     sudo docker --version
    

Installing Jenkins on Ubuntu :

  1. Update System:
sudo apt update
  1. Install Java (OpenJDK 17 preferred):
sudo yum install java-17-openjdk-headless java-17-openjdk-devel

Verify Java:

java -version
  1. Add Jenkins GPG Key and Repository:
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
  https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
  1. Update Package Lists:
sudo apt update
  1. Install Jenkins:
sudo apt install jenkins
  1. Start and Enable Jenkins:
sudo systemctl start jenkins
sudo systemctl enable jenkins
  1. Access Jenkins :

    Open http://localhost:8080/ in your browser.

Installing Jenkins on CentOS:

  1. Update System:
sudo yum update -y
  1. Install Java (OpenJDK 17 preferred):
sudo yum install java-17-openjdk-headless java-17-openjdk-devel

Verify Java:

java -version
  1. Add Jenkins GPG Key and Repository:
wget -q -O - https://pkg.jenkins.io/centos-stable/jenkins.io.key | sudo rpm --import -
sudo cat > /etc/yum.repos.d/jenkins.repo << EOF
[jenkins]
name=Jenkins
baseurl=https://pkg.jenkins.io/centos-stable/
gpgkey=https://pkg.jenkins.io/centos-stable/jenkins.io.key
enabled=1
autorefresh=1
gpgcheck=1
EOF
  1. Update Package Lists:
sudo yum update -y
  1. Install Jenkins:
sudo yum install jenkins
  1. Start and Enable Jenkins:
sudo systemctl start jenkins
sudo systemctl enable jenkins
  1. Access Jenkins:

Open http://localhost:8080/ in your browser.

Exploring Systemd and Systemctl

What is Systemd? Systemd is a system and service manager for Unix-like operating systems, designed to replace the traditional init system. It serves as the central hub for managing system services, handling tasks such as service startup, shutdown, and dependency management.

What is systemctl? Systemctl is a command-line utility used to examine and control the state of systemd units, including services, sockets, devices, and more. It provides a comprehensive set of commands for managing system services and querying their status.

Status of Jenkins Service before and after stopping

Before Stopping:

After Stopping:

Managing Services with systemctl vs service

Using systemctl:

systemctl status docker

Using service:

service docker status

While both systemctl and service commands can be used to manage system services, systemctl offers more advanced functionalities and is recommended for use with systemd-based systems. It provides granular control over service units and offers a unified interface for managing system services.

Conclusion

By mastering package managers and systemd, you gain the ability to manage software installations and system services effectively, enhancing the stability and performance of your Linux system. Take the time to explore these tools further, experiment with different commands, and deepen your understanding of Linux system management.