Day 7 Task: Understanding package manager and systemctl
Introduction
A package manager automates the installation, updating, and removal of software packages on a system by utilizing software repositories and managing dependencies. Examples include APT for Debian-based systems and YUM/DNF for Red Hat-based systems. On the other hand, systemctl is a command-line utility in Linux systems that interacts with the systemd
system and service manager. With systemctl
, administrators can control system services, including starting, stopping, and checking their status. It works through unit files that define service behaviors and integrates with tools like journalctl
for system logging. In essence, while a package manager handles software packages, systemctl
focuses on managing system services on a Linux platform.
What is a package manager in Linux?
In simpler words, a package manager is a tool that allows users to install, remove, upgrade, configure and manage software packages on an operating system. The package manager can be a graphical application like a software center or a command line tool like apt-get or pacman.
What is a package?
A package is usually referred to an application but it could be a GUI application, command line tool or a software library (required by other software programs). A package is essentially an archive file containing the binary executable, configuration file and sometimes information about the dependencies.
Different kinds of package managers
Package Managers differ based on the packaging system but the same packaging system may have more than one package manager.
For example, RPM has Yum and DNF, package managers. For DEB, you have apt-get, aptitude command line-based package managers.
Examples:
APT (Advanced Package Tool): Used primarily by Debian and Ubuntu systems.
YUM/DNF: Used by Red Hat, CentOS, and Fedora systems.
Homebrew: Popular on macOS for managing software.
Pacman: Used by Arch Linux and its derivatives.
- Installing Docker and Jenkins
Installing Docker and Jenkins Using Package Manager:
Install Docker for Ubuntu:
Open your terminal or Ec2 terminal and execute bellow commands.
First Update your package index:
sudo apt-get update
sudo apt-get install docker
docker --version
Install Docker for CentOs:
Open your terminal or Ec2 terminal and execute bellow commands.
sudo yum update sudo yum install docker
Install Jenkins on Ubuntu & CentOs:
To install Jenkins on Ubuntu and CentOS, both can use Java, so we need to install JDK (Java Development Kit) using the below commands.
For Ubuntu:
sudo apt update sudo apt install default-jdk
Install Jenkins on ubuntu:
sudo apt install jenkins
For CentOs:
sudo yum update sudo yum install java-devel
Install Jenkins on CentOs:
sudo yum install jenkins
Understanding systemctl , systemd and Service?
Systemd is a system and service manager for Linux operating systems. It is responsible for bootstrapping and managing processes. Systemctl is a command-line interface used to control and interact with systemd services. It can examine the status of units and targets, as well as start, stop, and reconfigure them. By mastering both components, users can efficiently manage and maintain their Linux systems.
What is Systemd?
Systemd is an init system used in Linux distributions to bootstrap user space components and manage system processes. It was designed to overcome the limitations of traditional init systems, such as SysV and Upstart, and to simplify the process of managing system services.
The key features of systemd include:
Parallelization: Systemd can start multiple services simultaneously, reducing boot time and improving system performance.
Dependency management: Systemd manages service dependencies automatically, ensuring that required services are started in the correct order.
Logging: Systemd incorporates the journald logging system, which collects and stores logs for all system components, making it easier to troubleshoot issues.
Cgroups integration: Systemd uses Control Groups (cgroups) to track and manage processes, enhancing resource management and process isolation.
Configuration files: Systemd uses unit files, which are simple text files, to define and configure services, making it easier to manage and customize system components.
What is Systemctl?
The systemctl command is a command-line utility that interacts with the systemd system and service manager. It is the primary tool used to control and manage systemd services, allowing users to start, stop, enable, disable, and check the status of services.
Some common systemctl commands include:
Start a service:-
systemctl start SERVICE_NAME
Stop a service:-
systemctl stop SERVICE_NAME
Restart a service:-
systemctl restart SERVICE_NAME
Enable a service to start at boot:-
systemctl enable SERVICE_NAME
Disable a service from starting at boot:-
systemctl disable SERVICE_NAME
Check the status of a service:-
systemctl status SERVICE_NAME
List all running services:-
systemctl list-units –type=service
Difference Between Systemd and Systemctl
Systemd is the init system and service manager responsible for managing system processes, while systemctl is the command-line interface used to interact with and control systemd. In summary:
Systemd is the underlying system that manages services, processes, and resources.
Systemctl is a command-line tool used to interact with and control systemd services and components.
Using Systemctl we can check the status of Docker service:
systemctl status docker
Start the Docker service:
sudo systemctl start docker
Stop the docker service:
sudo systemctl stop docker
Enable docker service:
sudo systemctl enable docker
What is Service ?
The service
command is a utility used for managing services in various Linux distributions. It acts as a wrapper for different init systems, allowing you to interact with services regardless of the underlying system. With service, you can start, stop, restart, reload, and check the status of services. It also enables or disables services to automatically start at boot time. This command provides a consistent interface, abstracting the differences between various init systems, making it useful for transitioning between different Linux distributions.
Examples:
check the docker service:
service docker status
start the docker service:
sudo service docker start
stop the docker service:
sudo service docker stop
restart the docker service:
sudo service docker restart
Conclusion
Understanding package managers and systemctl
is essential for effective system management in Linux. Package managers automate software tasks, while systemctl
provides a user-friendly interface to control and manage system services. Together, they streamline operations, ensuring efficient software installations, updates, and service configurations, especially crucial for DevOps and system administration tasks.
Subscribe to my newsletter
Read articles from Aesha Shah directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by