Linux Package Managers and systemctl

Linux Package Managers and systemctl

#90DaysofDevOps Challenge - Day 7

Table of contents

No heading

No headings in the article.

Each Linux distribution has its own package format (combination of metadata, configuration, and software) and a built-in package manager that allows you to install, update, and remove the software.

There are also third-party package managers that are designed to make life easier for the user. Each package manager has its own unique way of downloading and installing software, maintaining the system, handling dependencies, and uninstalling software.

Most package managers were developed to perform the same tasks, and many of them have similar functionality. Any package manager can install, uninstall, and update software and handle dependencies.

Most of them can work with online repositories and local packages.

▶APT package manager

APT (Advanced Package Tool) is a more advanced front-end for dpkg (Debian Package), the lowest-level package management system for Debian-based Linux distributions. APT is a powerful command-line package management tool providing an interface for better interactive usage. As with dpkg, APT can install, remove, and build packages.

The advanced functionality of APT is that it can update your packages and automatically install dependencies. It also provides command-line tools for searching, managing, and querying package information.

Packages are taken from online repositories, or they can be installed from local media. The list of package sources is stored in the /etc/apt/sources.list file and the /etc/apt/sources.list.d/ directory.

Common APT commands

$sudo apt update

To get the latest updates:

$sudo apt list --upgradable

To list down the packages that can be upgraded:

$sudo apt upgrade -y

To upgrade all these packages, we will run the upgrade using the APT package manager and also use the “-y” flag, so it will not ask for confirmation and just upgrade all the packages:

$sudo apt install --only-upgrade nano

To upgrade any specific package instead of all the packages you have to run them with –only-upgrade and the name of the package:

$sudo apt list

To list down all the packages available on the Operating System:

$sudo apt list --installed

To list down only installed packages:

$sudo apt search vim

To search for a specific package:

▶YUM package manager

YUM (Yellow Dog Updater) is the most popular choice as front-end for RPM, the basic package management software for RHEL operating systems.

YUM was designed to make it easier to work with distribution updates by keeping track of dependencies between packages.

YUM allows users to configure automated software updates and dependency resolution. The YUM manager works with package repositories from the distribution manufacturer or third-party authors. It is possible to create local or offline copies of the repositories or access them via the Internet.

YUM can perform such operations as searching for packages in repositories, installing packages from repositories, installing packages from .rpm files, updating the system, removing packages, and downgrading packages.

The main configuration file for YUM is /etc/yum.conf, and additional configuration files are also read from the directory /etc/yum.repos.d

This is a sample output of yum.conf

Common YUM commands

$sudo yum update

To update the package list of the system:

$sudo yum repolist

To list only enabled repositories:

$sudo yum search docker

To search for a specific package:

$sudo yum -y install docker-ce

To install a package:

$sudo yum list docker-ce

To list for a specific package:

▶DNF package manager

DNF (Dandified Packaging Tool) is a package manager that installs, updates, and removes packages on RPM-based Linux distributions. It is a more advanced version of the YUM manager and is intended to be the replacement for YUM in RPM-based systems.

DNF was introduced in Fedora 18. Now, it is the default package manager of Fedora 22, CentOS8, and RHEL8.

DNF is able to automatically compute dependencies and determine the actions required to install packages. DNF also makes it easier to maintain groups of machines by eliminating the need to manually update each one with RPM. It provides a strict API for extensions and plugins that can modify or extend features of DNF or provide additional CLI commands on top of standard commands.

It supports multiple repositories and package groups, including multiple-repository groups.

Common DNF commands

$sudo dnf update

To update the package list of the system:

$sudo dnf repolist

To list only enabled repositories:

$sudo dnf search docker

To search for a specific package:

$sudo dnf -y install docker-ce

To install a package:

$sudo dnf list docker-ce

To list for a specific package:

▶Install Docker and Jenkins packages on Ubuntu and CentOS using APT and YUM package managers

UBUNTU

Docker Install

To install Docker and check the state of the service:

$sudo apt install docker.io -y
$sudo systemctl status docker

Jenkins Install

Installing Java as a prerequisite.

$sudo apt install openjdk-11-jdk -y

Adding the repository key to the system.

$curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null

Append the Debian package repository address to the server’s sources.list

$sudo 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

Updating the list of packages:

$sudo apt-get update

To install Jenkins and check the state of the service:

$sudo apt-get install jenkins
$sudo systemctl status jenkins

CentOS

Docker Install

Adding the repository key to the system.

$sudo dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Install the latest version of Docker and check the state of the service:

$sudo dnf -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
$sudo systemctl start docker
$sudo systemctl status docker

▶Linux Initialization Process

On startup, Linux follows a set of pre-defined boot sequences and at the last step of the boot process, it runs an init system.

The init system serves as the first process in the user space and is responsible for starting up other important services and processes.

There are two most relevant init systems in Linux, namely System V init (SysVInit) and SystemD.

▶SysVInit and SystemD

SysVInit is the classic initialization process in Linux. The initialization process relies on the individual service to install relevant scripts on the /etc/init.d directory. Additionally, the scripts must support standard commands such as start, stop, and status. The service command is used for running these init scripts from the terminal.

SystemD, on the other hand, is a recent initialization system that aims to replace SysVInit. Most Linux distributions such as Debian and Red Hat are already using SystemD as their init system out of the box. SystemD continues to run as a daemon process after the initialization is completed. The systemctl command is the entry point for users to interact and configures the SystemD.

In short, the differences between service and systemctl commands can be summarized as two different commands for two different init systems.

service Commands

$sudo service docker start
$sudo service docker stop
$sudo service docker restart
$sudo service docker status

systemctl Command

We could also enable the Docker service so that it is automatically started on system startup. To do that, we use the systemctl enable command:

$sudo systemctl enable docker

On the other hand, to remove it from the startup process list, we use the systemctl disable command:

$sudo systemctl disable docker

▶Summary

In this article, we have explored the concepts of Package Managers and the Initialization process in Linux. For better understanding, we have demonstrated using some examples.