Understanding package manager and systemctl

Understanding package manager and systemctl

What is a package manager in Linux?

  • 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 center or a command line tool like apt-get or yum. To understand a package manager, you must understand what a package is.

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

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

  • For example, RPM has Yum and DNF, package managers. For DEB, you have apt-get aptitude command, line-based package managers.

Install docker and Jenkins in your system from your terminal using package managers.

    1. Docker installation :

      1. Update your system packages by running the following command:

        sudo yum update

      2. Install Docker:

        sudo yum install docker

        (if docker is present in your system it will install or you have to setup the repository and dependency, for more details. https://docs.docker.com/engine/install/rhel/ )

      3. Verify that the Docker installation is successful.

        which docker

        docker --version

      4. Start the Docker service:

        sudo systemctl start docker

      5. Verify that Docker is running correctly by running the following command:

        sudo docker run hello-world

      1. Downloading and installing Jenkins

        1. Ensure that your software packages are up to date on your instance

          sudo yum update -y

        2. Add the Jenkins repo using the following command:

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

        3. Import a key file from Jenkins-CI to enable installation from the package:

          sudo amazon-linux-extras install java-openjdk11 -y

        4. Install Java (Amazon Linux 2023):

          sudo yum install java-11-amazon-corretto -y

        5. Install Jenkins:

          sudo yum install jenkins -y

        6. Enable the Jenkins service to start at boot:

          sudo systemctl enable jenkins

        7. Start Jenkins as a service

          sudo systemctl start jenkins

        8. You can check the status of the Jenkins service using the command:

          sudo systemctl status jenkins

        9. unlock Jenkins

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

What are systemctl and systemd?

  • systemctl and systemd are tools used in modern Linux systems to manage system services and processes.

  • systemd is a system and service manager for Linux operating systems. It is responsible for starting up and managing system services, handling power management, and performing many other tasks that were traditionally handled by the init process. systemd is designed to provide a more reliable and efficient system startup and management experience.

  • systemctl is the command-line interface for interacting with the systemd system and service manager. It allows you to manage and control the state of system services, including starting, stopping, restarting, enabling, and disabling them. You can also use systemctl it to view the status of services and get information about service dependencies and logs.

  • With systemctl, you can easily manage and troubleshoot system services, monitor system health, and perform a variety of other administrative tasks. systemd and systemctl are widely used in modern Linux distributions and are an important part of the Linux ecosystem.

check the status of the docker service in your system

  • sudo systemctl status docker

stop the service Jenkins and post before and after screenshots

  1. Before

    sudo systemctl status jenkins

  2. After

    sudo systemctl stop jenkins

    sudo systemctl status jenkins

Read about the commands systemctl vs service

  • systemctl and service are both command-line tools used for managing services in Linux systems. However, there are some differences between the two.

  • systemctl

    service

    systemctl is a more modern and powerful command that is used in newer Linux distributions. It is used to manage the systemd system and service manager, which replaces the traditional init system. systemctl can perform the same tasks as the service, but it has additional functionality and features, such as the ability to view the status of a service, enable or disable a service at boot time, and more.

    service is a legacy command that is still used in many Linux distributions. It is used to manage the system services by starting, stopping, restarting, or reloading them. It works by executing scripts located in the /etc/init.d directory.

    For example, if you want to start the Apache web server using systemctl, you would run the following command: sudo systemctl start apache2

    For example, if you want to start the Apache web server using the service, you would run the following command: sudo service apache2 start

  • Additionally, systemctl has a number of subcommands that allow you to perform more advanced tasks, such as listing all running services, checking the status of a service, or getting information about a service's configuration.

  • Overall, while service is still supported in many Linux distributions, systemctl provides a more advanced and flexible way to manage services and is the preferred method in many modern Linux systems.