Understanding package manager and systemctl

Introduction:

This blog explores Linux package managers, covering Debian and RedHat-based systems, along with custom and project-specific managers. It offers a step-by-step guide for Jenkins and Docker installation on Ubuntu and CentOS, essential for CI/CD and containerization. Additionally, it introduces Systemd and Systemctl for service management, including commands and practical examples.

Package manager

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 centre or a command lines tool like apt-get or pacman.

Package Managers differ based on the packaging system, but the same packaging system may have more than one package manager.

Debian-Based Package Managers:

  • dpkg: Ubuntu and Debian use this as their lowest-level package management system. It is a bare-bones package management software, with tools for installing, removing, and building packages.

  • APT: Short for Advanced Package Tool, it is much more advanced in functionality when compared to dpkg. It can update your packages, install dependencies automatically, as well as download your packages from the internet automatically.

  • Aptitude: It offers most of the same functionality as APT. But, it can offer a couple of extra features, such as safety upgrades and package holding.

RedHat Enterprise Linux (RHEL)-Based Package Managers:

  • RPM: Created by Red Hat. RPM is the Linux Standard Base packaging format.

Other Custom-Designed Package Managers:

  • Pacman: Used in Arch Linux, Frugalware and DeLi Linux.

Note:- Please note that this is not an exhaustive list, there are many more package managers available. like Project and Programming Language-Specific Package Managers:

  • Pip: Installs system and project-level Python packages.

  • Maven & Gradle: Manage dependencies and the build process for Java projects.

  • npm: Installs and tracks JavaScript dependencies.

  • NuGet: Manages dependencies for .NET projects.

Package managers are crucial as they streamline the process of installing and updating software on Linux distributions. They handle dependencies, meaning they’re capable of automatically downloading and installing any additional software your chosen package might need to function correctly.

Before installing any package, it is important to add its repository because that’s where your system will look for updates for that package. If a repository is not added, your system won’t know where to find updates when they’re available.

Task-1

Installing Jenkins and Docker on Ubuntu

Installing Jenkins on Ubuntu:

Step 1: Update Your Package Lists Before installing any software, it's a good practice to ensure that the package is already available or not.

Command:

sudo systemctl status jenkins

Explanation:- This command checks the status of Jenkins, whether it is already installed or not?

Also, ensure that your system's package lists are up-to-date. Open your terminal and run the following command:

Command:

sudo apt update

Explanation:- This command updates the package lists from the repositories.

Step 2: Install Jenkins Jenkins can be installed on Ubuntu using the following commands:

Command:

sudo apt install openjdk-11-jre-headless -y

Explanation:- sudo apt install openjdk-11-jre-headless -y: This command installs the Java Runtime Environment (JRE) which is required to run Jenkins.

Command:

wget -q -O - pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -

Explanation:- wget -q -O - pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -: Adds the Jenkins repository key.

Command:

sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'

Explanation:- sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list': Adds the Jenkins repository to the list of sources.

Command:

sudo apt update

Explanation:- sudo apt update: Updates the package lists again.

Command:

sudo apt install jenkins -y

Explanation:- sudo apt install jenkins: Finally, installs Jenkins.

Step 3: Start and Enable Jenkins After installation, start the Jenkins service and enable it to start on boot

Commands:

sudo systemctl start jenkins

sudo systemctl enable jenkins

sudo systemctl status jenkins

Explanation:- To start, enable and check status of the jenkins package.

Installing Docker on Ubuntu:

Step 1: Use below commands to install Docker on Ubuntu OS

Command:

sudo apt update

Explanation:- This command updates the package lists from the repositories.

Step 2: Install Docker Install Docker on Ubuntu using the following commands:

Command:

sudo apt install docker.io -y

Explanation:- This command installs the Docker engine.

Step 3: Start and Enable Docker

Commands:

sudo systemctl start docker

sudo systemctl enable docker

sudo systemctl status docker

Explanation:- To start, enable and check status of the Docker.

Installing Jenkins on CentOS:

Step 1: Update Your Package Lists On CentOS, begin by updating the package lists:

Command:

sudo yum update

Explanation:- To update the package lists.

Step 2: Install Jenkins:

Commands:

sudo Install Jenkins on CentOS using the following commands:

sudo yum install java-11-openjdk-devel -y

sudo yum install wget

sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo

sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

sudo yum clean packages

sudo yum install jenkins -y

Explanation:-

Step 3: Start and Enable Jenkins

Start the Jenkins service and enable it to start on boot:

Commands:

sudo systemctl start jenkins

sudo systemctl enable jenkins

sudo systemctl status jenkins

Explanation:- To start, enable and check status of the jenkins package.

Installing Docker on CentOS:

Step 1: Update Your Package Lists Update the package lists on CentOS:

Command:

sudo yum update

Explanation:- To update the package lists.

Step 2: Install Docker

Install Docker on CentOS with the following command:

Command:

sudo yum install docker

Explanation:- This command installs the Docker engine.

Step 3: Start and Enable Docker

Start the Docker service and enable it to start on boot:

Commands:

sudo systemctl start docker

sudo systemctl enable docker

sudo systemctl status docker

Explanation:- To start, enable and check the status of the docker service.

That’s it! We’ve installed Jenkins and Docker on Ubuntu and CentOS using package managers. Remember to start these services and enable them to start at boot.

Systemd and Systemctl

Systemd is a "system and service manager" for Linux operating systems. It’s designed to make boot-up speeds faster and manage system services more efficiently. It replaces the traditional System V init system and becomes the first process that gets executed in user space during the Linux start-up process. Its main aim is to unify service configuration and behaviour across Linux distributions.

Systemctl is a command-line utility that controls and manages systemd. It allows you to examine and control the state of systemd system and service manager. With various commands, systemctl can start, stop, enable, disable services, check the status of services, and much more.

The systemctl commands to manage the services in linux:

  • To start a service: systemctl start [service-name]

  • To stop a service: systemctl stop [service-name]

  • To restart a service: systemctl restart [service-name]

  • To check the status of a service: systemctl status [service-name]

  • To enable a service at boot: systemctl enable [service-name]

  • To disable a service: systemctl disable [service-name]

Task-2

1) check the status of docker service in your system.

Command:

systemctl status docker

Output result:

2) stop the service jenkins and post before and after screenshots

Screenshot Before:

Command: Command to stop the Jenkins is

systemctl stop jenkins

Screenshot After:

I hope you enjoy the blog post!

If you find the blog helpful, please do like it and share it with your friends. If you have any doubts or questions related to the topics covered in the blog, feel free to ask them in the comments section. I’ll be more than happy to help!