Day7- Understanding the concept of package manager and systemctl

Day7- Understanding the concept of package manager and systemctl

What is a package manager in Linux?

A package manager is a software tool used to automate the process of installing, updating, configuring, and removing software packages on a Linux-based operating system. It automates tasks such as dependency resolution, ensuring that all required software components are installed for a particular package to function properly. Here are some key functions of a package manager:

  1. Package Installation: Package managers allow users to easily install software packages from centralized repositories.

  2. Dependency Resolution: Many software packages depend on other software libraries or components to function correctly. Package managers automatically handle resolving and installing these dependencies, ensuring that the software works as expected.

  3. Package Updates: Package managers can check for updates to installed software packages and download and install newer versions as they become available. This helps users keep their software up-to-date with the latest bug fixes, security patches, and features.

  4. Package Removal: When software is no longer needed, package managers make it easy to remove it from the system cleanly, including any dependencies that are no longer needed by other software.

  5. Configuration Management: Some package managers also handle configuration files associated with installed software, allowing users to manage software settings and preferences.

  6. Repository Management: Package managers interact with repositories, which are collections of software packages hosted on servers. They allow users to search, browse, and access available software packages from these repositories.

What is a package?

In Linux, a package refers to a compressed archive file that contains files and metadata necessary for the installation, configuration, and maintenance of software applications and libraries. Packages are commonly used in Linux distributions to manage software installation, updates, and removal. They are often distributed through centralized repositories maintained by the distribution's community or developers.

Packages come in various formats depending on the Linux distribution and the package management system used. Some common package formats include:

  1. Deb packages (.deb): Used primarily in Debian-based distributions such as Ubuntu, Debian, and Linux Mint. These packages are installed using the APT (Advanced Package Tool) package management system.

  2. RPM packages (.rpm): Commonly used in Red Hat-based distributions such as CentOS, Fedora, and RHEL (Red Hat Enterprise Linux). These packages are installed using package managers like YUM (Yellowdog Updater, Modified) or DNF (Dandified YUM).

  3. Pacman packages (.pkg.tar.xz): Used in Arch Linux and its derivatives. These packages are managed using the Pacman package manager.

  4. Tarballs (.tar.gz, .tar.bz2, .tar.xz): While not traditional package formats, tarballs are compressed archives containing source code or precompiled binaries. They are often used in distributions where packages are built from source, such as Gentoo or Slackware.

  5. Snap packages: A universal package format developed by Canonical for Ubuntu and other Linux distributions. Snap packages contain all the dependencies needed to run the software and can be installed across different Linux distributions.

These package formats encapsulate software in a standardized way, making it easier for users to install and manage software on their Linux systems while ensuring consistency and reliability.

What are the different kinds of package managers?

There are several package managers used in various Linux distributions, each with its own characteristics and syntax. Here are some of the most prominent ones:

  1. APT (Advanced Package Tool):

    • Used primarily in Debian-based distributions such as Ubuntu, Debian, and Linux Mint.

    • Uses .deb packages.

    • Commands include apt-get, apt, apt-cache.

  2. YUM (Yellowdog Updater, Modified):

    • Commonly used in Red Hat-based distributions such as CentOS, Fedora, and RHEL (Red Hat Enterprise Linux).

    • Uses .rpm packages.

    • Commands include yum.

  3. DNF (Dandified YUM):

    • An evolution of YUM, used in modern versions of Fedora and CentOS/RHEL starting from version 8.

    • Commands include dnf.

  4. Pacman:

    • Used in Arch Linux and its derivatives like Manjaro.

    • Uses its own .pkg.tar.xz packages.

    • Commands include pacman.

  5. ZYpp:

    • Used in SUSE Linux distributions like openSUSE and SUSE Linux Enterprise Server/Desktop.

    • Uses .rpm packages.

    • Commands include zypper.

  6. Portage:

    • Used in Gentoo Linux.

    • Packages are installed from source code using ebuild scripts.

    • Commands include emerge.

  7. Snap:

    • A universal package format developed by Canonical, the company behind Ubuntu.

    • Works across different Linux distributions.

    • Commands include snap.

  8. Flatpak:

    • Another universal package format aimed at providing sandboxed applications that run across different Linux distributions.

    • Commands include flatpak.

Each package manager has its strengths and is tailored to its respective distribution's needs and philosophies. Some focus on stability and reliability (like APT and YUM/DNF), while others prioritize bleeding-edge software and customization (like Pacman and Portage). Universal package formats like Snap and Flatpak aim to provide software distribution that is independent of the underlying Linux distribution.

How to install Docker in your system from your terminal using package managers

To install Docker using a package manager, you need to first ensure that the package manager is set up correctly on your system. Below are instructions for installing Docker using package managers like APT (Advanced Package Tool) for Debian-based systems such as Ubuntu.

Using APT (Debian-based systems):

  1. Update the package index:
sudo apt-get update
  1. Install Docker:
 sudo apt-get install docker.io
  1. To check the Docker status:

     systemctl status docker
    
  2. To verify that Docker is installed and running, you can run:

     docker --version
    

    Congratulations! Docker is now installed on your system.

    How to install Jenkins in your system from your terminal using package managers

    Jenkins is a tool that automates repetitive tasks in software development, like building and testing code, making development and delivery faster and more efficient. It provides a platform for continuous integration and continuous delivery (CI/CD)

    Update the Package Index:

    Before installing any new software, it's a good practice to update the package index:

     sudo apt-get update
    

    Install Java:

    Jenkins requires Java to run. If you haven't already installed Java, you can install it using the following command:

     sudo apt install fontconfig openjdk-17-jre
     java --version
    

    Download and Install Jenkins:

    You can download and install Jenkins by adding the Jenkins Debian repository key to your system and then adding the repository itself. This can be done using the following commands:

     sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
       https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
     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
    

    Update Package Index Again:

    After adding the Jenkins repository, update the package index once more:

     sudo apt-get update
    

    Install Jenkins:

    Finally, install Jenkins:

     sudo apt-get install jenkins
    

    To check Jenkins Status:

    To check Jenkins is in active(running) state or not.

     systemctl status jenkins
    

    Unlock Jenkins:

    Open a web browser and access http://your_server_ip or domain:8080. You'll be prompted to enter an initial admin password. Retrieve the password using:

     sudo cat /var/lib/jenkins/secrets/initialAdminPassword
    

    What is systemctl and systemd?

    systemctl is the primary command-line tool for interacting with the systemd init system.systemctl is the interface through which users and administrators interact with the systemd init system to manage services and perform various system-related tasks.

    It allows you to control and manage system services, view their status, start or stop them, enable or disable them. It provides a user-friendly and standardized way to control and monitor services and the system's behavior.

Check the status of docker service in your system (make sure you completed above tasks, else docker won’t be installed)

How to stop the Jenkins service and post before and after screenshots

To stop Jenkins, you typically use the systemctl command if Jenkins is managed as a systemd service. Here's how you can stop Jenkins on a system where it's managed by systemd:

  1. Stop Jenkins Service:

    Use the systemctl command to stop the Jenkins service:

     sudo systemctl stop jenkins
    
  2. Verify Jenkins Status (Optional):

    You can optionally check the status of the Jenkins service to ensure it has stopped:

     sudo systemctl status jenkins
    

    This command will display information about the Jenkins service, including whether it's active or not.

Once you execute the stop command, Jenkins should be stopped on your system. If you need to start Jenkins again, you can use sudo systemctl start jenkins.

write about the commands systemctl vs service:

systemctl and service are both commands used to manage services on Linux systems, but they have some differences in terms of functionality and usage.

  1. Functionality:

    • systemctl: systemctl is a more powerful and feature-rich command that is used to control the systemd system and service manager. It can start, stop, restart, enable, disable, and manage services, as well as perform other systemd-related tasks like querying the status of services and displaying system logs.

    • service: service is a simpler command that provides a more user-friendly interface for managing services. It can start, stop, restart, and query the status of services. service is a wrapper around systemctl and works on systems with traditional init systems (SysVinit) as well as systems with systemd.

  2. Usage:

    • systemctl: The general syntax for systemctl is systemctl [option] [unit]. For example, to start the Apache HTTP server service, you would use sudo systemctl start apache2.

    • service: The general syntax for service is service [service-name] [action]. For example, to start the Apache HTTP server service, you would use sudo service apache2 start.

  3. Compatibility:

    • systemctl: systemctl is the preferred command for managing services on systems that use systemd as the init system, such as most modern Linux distributions (e.g., Ubuntu 16.04 and later, CentOS/RHEL 7 and later).

    • service: service is provided for backward compatibility with older Linux distributions that use traditional init systems like SysVinit. However, it also works on systems with systemd.

systemctl commands:

systemctl start <service-name>

systemctl stop <service-name>

systemctl restart <service-name>

systemctl enable <service-name>

systemctl disable <service-name>

systemctl status <service-name>

service commands:

service <service-name> start

service <service-name> status

service <service-name> stop

service <service-name> restart

Conclusion:

In summary, systemctl is the preferred choice for managing services on modern Linux distributions using the systemd init system. It offers more advanced features and flexibility compared to the more basic service utility associated with the older SysV init system. If you are using a distribution that utilizes, it is recommended to use systemctl for service management.

This is the #Day07 of the #90DaysofDevOps challenge! Hope you found this article informative and useful so please share it with others who might benefit from it.

Thanks for reading this article.

Keep Learning...