Understanding package manager and systemctl

Understanding package manager and systemctl

Day 7

1️⃣ What is a package manager in Linux?

In Linux, a package manager is a software tool that automates the process of installing, upgrading, configuring, and removing software packages within the operating system. It simplifies the management of software by handling dependencies, resolving conflicts, and providing a centralized repository of software packages.

The package manager keeps track of available software packages, their versions, and any dependencies they may have on other packages. It allows users to easily search for, install, and update software packages from a trusted source, ensuring that the software is obtained from reliable and authenticated repositories.

Package managers typically provide a command-line interface (CLI) as well as graphical user interfaces (GUI) to interact with the system. The CLI commands allow users to perform various operations such as installing, removing, updating, and searching for packages.

2️⃣ What is a package?

A package is a compressed archive file that contains files and metadata required for the installation and operation of a specific software program or library. It is a standardized format used to distribute software and its associated resources.

A package typically includes the following components:

  1. Executable files: These are the files that contain the actual program code or binaries that can be run on the operating system.

  2. Libraries: Many software packages rely on external libraries or frameworks to function properly. These libraries are included in the package to ensure that the software has all the necessary dependencies.

  3. Configuration files: These files contain settings and parameters that can be modified to customize the behavior of the software.

  4. Documentation: Packages often include documentation files that provide instructions, guidelines, and explanations on how to use the software effectively.

  5. Metadata: Packages contain metadata that describes the software, such as its name, version, author, license, and other relevant information. This metadata helps the package manager keep track of installed packages and resolve dependencies.

3️⃣ Different kinds of package managers.

Some popular package managers in Linux include:

  1. Advanced Package Tool (APT): Used by Debian-based distributions like Ubuntu, it uses .deb packages.

  2. Yellowdog Updater, Modified (YUM): Used by RPM-based distributions like Red Hat, CentOS, and Fedora, it uses .rpm packages.

  3. Pacman: Used by Arch Linux and its derivatives.

  4. DNF (Dandified YUM): A replacement for YUM in recent versions of Fedora and CentOS.

  5. Zypper: Used by SUSE Linux distributions.

Package managers make it easier to maintain software on Linux systems, as they handle updates, dependency resolution, and package verification. They ensure that software installations are consistent, efficient, and secure, contributing to the overall stability and reliability of the operating system.

4️⃣Install Docker and Jenkins in the Linux system from the terminal using package managers.

Docker Installation

If you want to install docker on Ubuntu then execute the below command,

$ sudo apt-get update -y
$ sudo apt-get install docker.io -y
#verify the service status with below 
$ sudo systemctl status docker
OR
$ service docker status

$If you want to install docker on RHEL then execute the below command,

$ sudo yum update -y
$ sudo yum install docker -y

If you want to install other tools along with Docker then you have to read the official document from Docker Docs

Jenkins Installation

Below is the code when I installed during this blog creation, so always go to the official website of Jenkins for the stable, LTS, and the latest releases.

#Install the dependencies 
$ sudo apt update
$ sudo apt install openjdk-11-jre
$ java -version
openjdk version "11.0.19" 2023-04-18 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.19.0.7-1.el9_1) (build 11.0.19+7-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.19.0.7-1.el9_1) (build 11.0.19+7-LTS, mixed mode, sharing)

#add the jenkins key ring in the device
$ curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null
$ 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
$ sudo apt-get update
$ sudo apt-get install jenkins
#verify the service status with below 
$ sudo systemctl status jenkins 
OR
$ service jenkins status

Post-installation setup wizard

After downloading, installing and running Jenkins using one of the procedures above (except for installation with Jenkins Operator), the post-installation setup wizard begins.

This setup wizard takes you through a few quick "one-off" steps to unlock Jenkins, customize it with plugins and create the first administrator user through which you can continue accessing Jenkins.

Unlocking Jenkins

When you first access a new Jenkins instance, you are asked to unlock it using an automatically-generated password.

  1. Browse to http://localhost:8080 (or whichever port you configured for Jenkins when installing it) and wait until the Unlock Jenkins page appears.

    Unlock Jenkins page

  2. From the Jenkins console log output, copy the automatically-generated alphanumeric password (between the 2 sets of asterisks).

    Note:

    • The command: sudo cat /var/lib/jenkins/secrets/initialAdminPassword will print the password at console.

    • If you are running Jenkins in Docker using the official jenkins/jenkins image you can use sudo docker exec ${CONTAINER_ID or CONTAINER_NAME} cat /var/jenkins_home/secrets/initialAdminPassword to print the password in the console without having to exec into the container.

  3. On the Unlock Jenkins page, paste this password into the Administrator password field and click Continue.
    Note:

    • The Jenkins console log indicates the location (in the Jenkins home directory) where this password can also be obtained. This password must be entered in the setup wizard on new Jenkins installations before you can access Jenkins’s main UI. This password also serves as the default administrator account’s password (with username "admin") if you happen to skip the subsequent user-creation step in the setup wizard.

5️⃣systemctl and systemd

systemctl and systemd are both core components of modern Linux distributions that adopt the systemd initialization system. Let's take a closer look at each of them:

  1. systemctl: systemctl is a command-line utility used to control and manage the systemd system and service manager. It provides a convenient interface for starting, stopping, restarting, enabling, disabling, and checking the status of services and units managed by systemd.

Here are some common systemctl commands:

  • systemctl start <service>: Start a service.

  • systemctl stop <service>: Stop a service.

  • systemctl restart <service>: Restart a service.

  • systemctl enable <service>: Enable a service to start automatically at boot.

  • systemctl disable <service>: Disable a service from starting automatically at boot.

  • systemctl status <service>: Check the status of a service.

  1. systemd: systemd is an initialization system and service manager that replaces the traditional SysV init system used in older Linux distributions. It is responsible for booting the system, managing system services, handling system events, and providing various features such as process tracking, logging, and resource management.

systemd introduces several key concepts:

  • Units: Units represent system resources or services that systemd manages. They can be services, sockets, devices, mounts, timers, and more. Units are defined by configuration files that specify how the resource should be handled.

  • Targets: Targets are logical groups of units that represent system states, such as multi-user mode or graphical desktop environment. Starting or stopping a target will automatically start or stop the units associated with it.

  • Journal: systemd provides a centralized logging system called the journal. It collects log messages from various sources and allows for advanced searching, filtering, and analysis of logs.

systemd and systemctl offer improved system initialization, parallelized startup processes, efficient service management, and advanced logging capabilities. They have become widely adopted in many Linux distributions, including Ubuntu, Fedora, CentOS, and others, providing enhanced system management and improved performance.

Thanks for reading the blog !