DEV Community

Cover image for Understanding Package Manager and Systemctl
FARUKH KHAN
FARUKH KHAN

Posted on

Understanding Package Manager and Systemctl

Package management is a fundamental part of any DevOps workflow. Whether you’re deploying applications, managing servers, or automating processes, a strong understanding of Linux package managers is essential. In this post, we'll break down the key concepts of package managers and explore some practical tasks, including installing and managing essential tools like Docker and Jenkins. Let’s dive in!

🌐 Package Manager in Linux

Simply put, a package manager is a tool that allows users to install, update, remove, and configure software on a Linux-based system. It handles packages, which are essentially software bundles. You can think of a package manager as the software's “delivery and maintenance” service.

Key Features of Package Managers:

Installation & Updates: Quickly install or update software packages.

Dependency Management: Resolve and install software dependencies automatically.

Configuration: Adjust package settings and configurations easily.

Removal: Safely uninstall software while ensuring dependencies remain intact.

Examples of common Linux package managers:

Debian-based systems (Ubuntu): apt-get

Red Hat-based systems (CentOS, Fedora): yum, dnf

Arch Linux: pacman

🛠️ Package

A package is more than just an application. It can include:

GUI applications

Command-line tools

Libraries required by other software

Each package typically comes as a compressed archive, including:

Binary executables: The main software components.

Configuration files: Essential for setup and operation.

Metadata: Information about dependencies and updates.

📦 Types of Linux Package Managers

Different Linux distributions come with different package management systems. Even within the same ecosystem, you might have multiple package managers:

Debian (DEB packages): apt-get, aptitude

RedHat (RPM packages): yum, dnf

Each of these tools helps in managing the lifecycle of software on your system—making it straightforward to install and maintain applications.

🚀 Hands-On DevOps: Installing Docker & Jenkins

Let’s now walk through installing Docker and Jenkins using package managers on both Ubuntu and CentOS.

Installing Docker & Jenkins on Ubuntu

Ubuntu, being a Debian-based distribution, uses the APT package manager. Here’s how to install Docker and Jenkins:

Installing Docker:

sudo apt update
sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docker
Enter fullscreen mode Exit fullscreen mode

Installing Jenkins:

sudo apt update
sudo apt install openjdk-11-jdk -y
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 update
sudo apt install jenkins -y
sudo systemctl start jenkins
sudo systemctl enable jenkins
Enter fullscreen mode Exit fullscreen mode

Installing Docker & Jenkins on CentOS

For CentOS, which is based on RedHat, you’ll use YUM or DNF as the package manager.

Installing Docker:

sudo yum install docker
sudo systemctl start docker
sudo systemctl enable docker
Enter fullscreen mode Exit fullscreen mode

Installing Jenkins:

sudo yum install java-11-openjdk
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
sudo yum install jenkins
sudo systemctl start jenkins
sudo systemctl enable jenkins
Enter fullscreen mode Exit fullscreen mode

💡 Tip: Always check for the latest version of Docker and Jenkins to ensure you're installing the most stable and secure versions!

🔄 Managing Services with systemctl and service

Now that Docker and Jenkins are installed, let’s manage their services using systemctl and service.

Systemd and Systemctl

Systemd is the system and service manager for most modern Linux distributions.

Systemctl is the tool that interacts with Systemd to control services like Docker and Jenkins.

Common systemctl commands:

Check Docker Status: sudo systemctl status docker

Stop Jenkins: sudo systemctl stop jenkins

Alternatively, the service command can also be used:

Check Docker Status: sudo service docker status

Stop Jenkins: sudo service jenkins stop

⚙️ Automating Docker and Jenkins Services

Here’s a simple script to automate the starting and stopping of Docker and Jenkins services. This can come in handy for system maintenance or automated deployment pipelines.

#!/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
Enter fullscreen mode Exit fullscreen mode

📌 Pro Tip: Save the script as manage_services.sh and make it executable using:

chmod +x manage_services.sh

Enter fullscreen mode Exit fullscreen mode

Run it whenever you need to manage these services.

🛠️ Additional Tasks for Service Management

Enable Docker on Boot:
Ensure Docker starts on system boot:

sudo systemctl enable docker

Enter fullscreen mode Exit fullscreen mode

Disable Jenkins on Boot:
Prevent Jenkins from starting on boot:

sudo systemctl disable jenkins

Enter fullscreen mode Exit fullscreen mode

Analyzing Logs with journalctl:
To get insights into service logs:

sudo journalctl -u docker
sudo journalctl -u jenkins
Enter fullscreen mode Exit fullscreen mode

📊 Systemctl vs. Service

You might come across two different commands— systemctl and service —when managing services in Linux. Let’s quickly break down their differences in a human-friendly way:

Systemctl is part of Systemd, the newer and more powerful system manager used by most modern Linux distributions. It provides more granular control over services, allowing you to manage units (like services) in a much more flexible way.

Example: sudo systemctl status docker 🐋

Service, on the other hand, is the older tool used in SysVinit (the init system before Systemd). It’s still available on most systems for backward compatibility, so if you're running an older Linux version or need a quick, simple command, you might use service.

Example: sudo service docker status 🖥️

Key Differences:

Systemctl offers more advanced and detailed features.

Service is simpler but more limited in functionality.

💡 Tip: Always use systemctl for more modern systems and better control!

🎯 Wrapping Up

Mastering package managers and service control tools like systemctl is crucial for DevOps professionals. Whether you’re installing new applications or ensuring services run smoothly, the right knowledge makes system administration much more efficient.

By automating tasks, controlling services, and analyzing logs, you can ensure that your environments remain healthy and responsive.

Happy coding, and keep automating! ✨

Top comments (0)