Day 7 : Understanding Package Manager and Systemctl

Understanding Package Managers in Linux


In Linux, a package manager is a vital tool for installing, removing, upgrading, configuring, and managing software packages on an operating system. Package managers can be graphical applications like a software center or command line tools like apt-get or pacman.


What is a Package?

A package is an archive file containing the binary executable, configuration files, and sometimes information about dependencies. Packages can be GUI applications, command-line tools, or software libraries required by other programs.


Different Kinds of Package Managers

Package managers differ based on the packaging system, but the same system may have multiple package managers. For example:

  • RPM: Uses yum and dnf.

  • DEB: Uses apt-get and aptitude.


Tasks

1. Install Docker and Jenkins

Ubuntu:

Install Docker:

sudo apt-get update
sudo apt-get install -y docker.io

Install Jenkins:

sudo apt-get update
sudo apt-get install -y openjdk-11-jdk
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install -y jenkins

๐Ÿ“ธ Screenshot:

Install Docker and Jenkins on Ubuntu

CentOS:

Install Docker:

sudo yum update -y
sudo yum install -y docker

Install Jenkins:

sudo yum install -y epel-release java-11-openjdk-devel
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo
rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key
sudo yum install -y jenkins

๐Ÿ“ธ Screenshot:

Install Docker and Jenkins on CentOS


Systemctl and Systemd

systemctl is used to examine and control the state of the systemd system and service manager. systemd is a system and service manager for Unix-like operating systems.

Tasks

Check Docker Service Status:

systemctl status docker

๐Ÿ“ธ Screenshot:

Docker Service Status

Manage Jenkins Service:

Stop Jenkins Service:

sudo systemctl stop jenkins

๐Ÿ“ธ Before Stopping Jenkins:

Before Stopping Jenkins

๐Ÿ“ธ After Stopping Jenkins:

After Stopping Jenkins

Read About Systemctl vs. Service:

  • systemctl: Controls the state of systemd services.

  • service: An older command used for managing services in SysVinit.

Example:

systemctl status docker
service docker status

Additional Tasks

Automate Service Management

Create a script to automate starting and stopping Docker and Jenkins services.

#!/bin/bash

echo "Starting Docker and Jenkins services..."
sudo systemctl start docker
sudo systemctl start jenkins

echo "Stopping Docker and Jenkins services..."
sudo systemctl stop docker
sudo systemctl stop jenkins

๐Ÿ“ธ Screenshot:

Service Management Script

Enable and Disable Services

Enable Docker to start on boot:

sudo systemctl enable docker

Disable Jenkins from starting on boot:

sudo systemctl disable jenkins

๐Ÿ“ธ Screenshot:

Enable and Disable Services

Analyze Logs

Use journalctl to analyze Docker and Jenkins logs.

journalctl -u docker
journalctl -u jenkins

๐Ÿ“ธ Screenshot:

Analyze Logs


Conclusion

Package managers are essential tools for managing software on Linux systems. Understanding how to use package managers, systemctl, and journalctl is crucial for effective system administration and automation. Happy managing! ๐ŸŽ‰

0
Subscribe to my newsletter

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

Written by

Himanshu Palhade
Himanshu Palhade