# DAY - 7  Understanding package manager and systemctl

## Introduction:

* Package managers are powerful tools that form the backbone of software management in Linux-based operating systems.
    
* They play a crucial role in simplifying the installation, updating, and removal of software packages, making it easier for users and system administrators to manage applications, libraries, and dependencies seamlessly.
    
* From **Ubuntu's APT (Advanced Package Tool)** to **Fedora's DNF (Dandified Yum)**, each package manager brings its unique set of features and benefits.
    

## What are Package Managers?

Package managers are tools designed to make your life easier. They help you install, update, and remove software on your Linux system. Think of them as app stores or one-stop shops for software.

## Different kinds of package managers:

There are several types of package managers used in Linux distributions, each designed to serve specific needs and requirements. The major types of package managers are:

1. dpkg (Debian Package Manager):
    
    Used in Debian-based distributions like Debian itself, Ubuntu, Linux Mint, and others. It handles individual package management and works with .deb packages.
    
2. APT (Advanced Package Tool):
    
    A front-end for dpkg, APT manages software repositories and simplifies package installation, updating, and removal. It is commonly used in Debian-based distributions.
    
3. RPM (Red Hat Package Manager):
    
    Used in Red Hat-based distributions like Red Hat Enterprise Linux (RHEL), CentOS, Fedora, and others. RPM handles individual package management and works with .rpm packages.
    
4. YUM (Yellowdog Updater Modified):
    
    Used in older versions of RHEL and CentOS. It has been replaced by DNF in newer distributions.
    

Each package manager has its own commands, syntax, and specific features, but their core purpose is to simplify software management and ensure a smooth and reliable experience for Linux users.

Users can choose the distribution that best fits their needs and preferences, taking into account the package manager it uses.

## Task 1: You have to install the docker using package managers:

Below are the general steps for installing Docker using package managers:

1. **Install Docker:** Docker is widely available for most Linux distributions. Here's how you can install Docker using the package manager for different distributions:
    

**For Debian/Ubuntu-based distributions (using APT):**

```plaintext
sudo apt update
sudo apt install docker.io -y
```

**For Red Hat/CentOS-based distributions (using YUM):**

```plaintext
sudo yum install docker
```

For Fedora (using DNF):

```plaintext
sudo dnf install docker
```

1. **Start and Enable Docker Service:** After installing Docker, start and enable the Docker service to ensure it starts automatically upon system boot.
    

```plaintext
sudo systemctl start docker
sudo systemctl enable docker
```

## Task 2 : You have to install Jenkins using package managers:

1. **Install Jenkins:** Jenkins is not typically available in the official package repositories, but it can be installed using package managers with the help of additional repositories or packages designed for Jenkins.
    
    For Debian/Ubuntu-based distributions:
    
    ```plaintext
    # Add the Jenkins repository key
    wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
    
    # Add the Jenkins repository to the package sources
    sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
    
    # Install Jenkins
    sudo apt update
    sudo apt install jenkins
    ```
    
    For Red Hat/CentOS-based distributions:
    
    ```plaintext
    # Add the Jenkins repository
    sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins.io/redhat/jenkins.repo
    
    # Import the Jenkins repository key
    sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key
    
    # Install Jenkins
    sudo yum install jenkins
    ```
    
    1. **Start and Enable Jenkins Service:**
        
        After installing Jenkins, start and enable the Jenkins service to run it as a background process.
        
        ```plaintext
        sudo systemctl start jenkins
        sudo systemctl enable jenkins
        ```
        

Once Docker and Jenkins are successfully installed and their services are running, you can access Docker and Jenkins through their respective interfaces.

Docker can be accessed through the terminal commands, while Jenkins can be accessed via a web browser at [http://localhost:8080](http://localhost:8080) (by default).

## Understanding "systemctl "and "systemd".

systemctl and systemd are essential components in modern Linux systems, responsible for managing and controlling system services and processes. Let's explore each of them in detail:

1. **Systemd:**
    
    systemd is the superhero that manages all the services and processes in your Linux system. It's like the conductor of an orchestra, making sure everything runs smoothly.
    
    **Example**: When you start your computer, systemd takes care of booting up all the essential services and applications in the right order. It ensures that your networking, display, and other critical components are ready for you to use.
    
    Another Example: systemd can automatically restart crashed services. If a service encounters an issue, systemd quickly brings it back up, so you won't even notice a problem.
    
2. **Systemctl:**
    
    systemctl is like your command center to talk to systemd. It's like having a remote control for all the services on your Linux system.
    
    Example: Let's say you want to start a service ex: apache2.
    
    You simply use systemctl to do it with one command:
    
    ```plaintext
    sudo systemctl start apache2
    ```
    
    **Another Example**: If you want to check if a service is running, you can ask systemctl:
    
    ```plaintext
    sudo systemctl status ssh
    ```
    
    You can also stop or restart services easily with systemctl:
    
    ```plaintext
    sudo systemctl stop nginx
    sudo systemctl restart mysql
    ```
    
    And if you want a service to start automatically every time your computer boots up, you can enable it:
    
    ```plaintext
    sudo systemctl enable mongodb
    ```
    
    **systemctl** makes it super simple to manage all your services, just like having a handy tool to control everything in your Linux system.
    
    Both **systemd** and **systemctl** work together to make your Linux experience smoother and more efficient. They take care of the background tasks, so you can focus on using your computer without worrying about the technicalities of managing services and processes.
    

## Task 3 : check the status of docker service in your system.

To check the status of the Docker service on Linux using **systemctl:**

```plaintext
systemctl status docker
```

If Docker is running, you will see an output similar to this:

```plaintext
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2023-07-24 10:00:00 EDT; 2h ago
     Docs: https://docs.docker.com
 Main PID: 1234 (dockerd)
    Tasks: 50
   Memory: 100.0M
      CPU: 10s
   CGroup: /system.slice/docker.service
           ├─1234 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
           └─5678 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 80 -container-ip 172.17.0.2 -container-port 80
```

If Docker is not running, the output might look like this:

```plaintext
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: https://docs.docker.com
```

In this case, you can start Docker using the following command:

```plaintext
sudo systemctl start docker
```

## Task 4 : stop the service jenkins:

To stop the Jenkins service on Linux, follow these steps:

1. Open a terminal or command prompt on your Linux system.
    
2. Use the following command to stop the Jenkins service:
    
    ```plaintext
    sudo systemctl stop jenkins
    ```
    
    This command will send a stop signal to the Jenkins service, and it will be stopped.
    
3. You can verify the status of the Jenkins service to confirm that it is no longer running:
    
    ```plaintext
    sudo systemctl status jenkins
    ```
    
    If the Jenkins service has been successfully stopped, you will see an output indicating that the service is inactive (dead).
    

Conclusion:

In conclusion, package managers play a important role in the world of Linux by simplifying software management and enhancing the user experience. They are powerful tools that enable users and administrators to install, update, and remove software packages effortlessly.

Package managers bring numerous benefits to the Linux ecosystem, making it easier to maintain a secure, up-to-date, and reliable system.

**Thank you for taking the time to read this blog.**

**I hope you found the information helpful and insightful.**
