Understanding Package Manager and Systemctl - Linux

Package Manager in Linux

A package manager is a software tool that helps users install, upgrade, configure, and manage software packages on their Linux systems. It is a critical component of any Linux distribution as it simplifies the process of installing and managing software on a Linux system.

Linux software packages are available in pre-compiled binaries or source code formats. Package managers automate the process of fetching, verifying, installing, and updating these packages. Additionally, package managers resolve dependencies, which are other packages that a package relies on, by downloading and installing them as necessary.

What is a package

A package is usually referred to as 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

There are several different package managers used in Linux. I will be focusing on the Advanced Package Tool (APT). Just to name a few:

  • apt: used in Debian, Ubuntu, and related distributions

  • yum/dnf: used in Fedora, CentOS, and related distributions

Installation of Docker

Before installing a package manager, it's always good to update your system. We can use the "sudo apt update" command. Once Docker is installed, you can check to see its version.

ubuntu@ip-172-31-61-13:~$ sudo apt-get update
ubuntu@ip-172-31-61-13:~$ sudo apt-get install docker.io
ubuntu@ip-172-31-61-13:~$ docker --version
Docker version 20.10.21, build 20.10.21-0ubuntu1~22.04.2

Installation of Jenkins

Again before installing Jenkins, you can update your system. To install Jenkins, Java should be installed first.

ubuntu@ip-172-31-61-13:~$ sudo apt update
ubuntu@ip-172-31-61-13:~$ sudo apt install openjdk-11-jre
ubuntu@ip-172-31-61-13:~$ java --version
openjdk 11.0.18 2023-01-17
OpenJDK Runtime Environment (build 11.0.18+10-post-Ubuntu-0ubuntu122.04)
OpenJDK 64-Bit Server VM (build 11.0.18+10-post-Ubuntu-0ubuntu122.04, mixed mode, sharing) 
ubuntu@ip-172-31-61-13:~$ sudo wget -O /etc/yum.repos.d/jenkins.repo \
    https://pkg.jenkins.io/redhat/jenkins.repo
ubuntu@ip-172-31-61-13:~$ sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io-2023.key
ubuntu@ip-172-31-61-13:~$ sudo dnf upgrade
ubuntu@ip-172-31-61-13:~$ sudo dnf install java-11-openjdk
ubuntu@ip-172-31-61-13:~$ sudo dnf install jenkins

"systemctl and "systemd"

"systemctl" is a system controller that gives you the status of all the services/tools installed in your system and can control it. It interacts with or overlooks a process named "systemd" which is running in the background. "D" stands for Daemon which refers to background processes. Here's an example of checking the status of Docker in our system.

ubuntu@ip-172-31-61-13:~$ systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2023-04-07 07:58:54 UTC; 1h 58min ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 741 (dockerd)
      Tasks: 7
     Memory: 21.8M
        CPU: 1.085s
     CGroup: /system.slice/docker.service
             └─741 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Apr 07 07:58:52 ip-172-31-61-13 dockerd[741]: time="2023-04-07T07:58:52.108160939Z" level=info msg="ccResolverWrapper>
Apr 07 07:58:52 ip-172-31-61-13 dockerd[741]: time="2023-04-07T07:58:52.108173689Z" level=info msg="ClientConn switch>
Apr 07 07:58:52 ip-172-31-61-13 dockerd[741]: time="2023-04-07T07:58:52.362526585Z" level=info msg="[graphdriver] usi>
Apr 07 07:58:52 ip-172-31-61-13 dockerd[741]: time="2023-04-07T07:58:52.397646348Z" level=info msg="Loading container>
Apr 07 07:58:53 ip-172-31-61-13 dockerd[741]: time="2023-04-07T07:58:53.584628279Z" level=info msg="Default bridge (d>
Apr 07 07:58:53 ip-172-31-61-13 dockerd[741]: time="2023-04-07T07:58:53.789698701Z" level=info msg="Loading container>
Apr 07 07:58:53 ip-172-31-61-13 dockerd[741]: time="2023-04-07T07:58:53.980717457Z" level=info msg="Docker daemon" co>
Apr 07 07:58:53 ip-172-31-61-13 dockerd[741]: time="2023-04-07T07:58:53.981602150Z" level=info msg="Daemon has comple>
Apr 07 07:58:54 ip-172-31-61-13 systemd[1]: Started Docker Application Container Engine.
Apr 07 07:58:54 ip-172-31-61-13 dockerd[741]: time="2023-04-07T07:58:54.062355208Z" level=info msg="API listen on /ru>
lines 1-22/22 (END)

The above shows that Docker is active and running. The same could be used for others as well such as Jenkins using the same command. "systemctl" can also assist with stopping a service/tool as well. "service" is another command which can be used as well to check the status of applications very similar to "systemctl" command. The differences between the 2 commands are the way the command is written and the "enable" command is used with "systemctl". If the machine is turned off or rebooted, the "enable" action allows that particular tool to run or be active every time the system boots up.

ubuntu@ip-172-31-61-13:~$ sudo systemctl enable docker

With the above example, Docker will be ready to run every time the system restarts.


I appreciate your busy time reading this short blog. As I continue with my journey to learn and acquire the skill set of a DevOps Engineer, I will share what I learn. Thank you.

Happy Learning!


Sam Samarullah

LinkedIn

Previous Blog