Day 7: 90DaysOfChallenge

Day 7: 90DaysOfChallenge

Understanding package manager and systemctl

In this post, we are going to learn about package managers, how to install tools like Docker and Jenkins using package managers on Ubuntu and also about systemctl and systemd commands.

  • What is Package Manager in Linux?

    In simple words, a package manager in Linux is like a digital "store" or "library" where we can find and download software applications, libraries, and other tools for our computer. It helps to easily install, update, and remove software without the need to search for individual files or worry about complex installation processes.

    It's a convenient way to browse and install software on the Linux system, similar to how we might use an app store on a smartphone. The package manager ensures that all the necessary files and dependencies are correctly installed, making it efficient and reliable to manage software on our Linux machine.

  • What is a package?

    A package is a single file or archive that includes all the necessary files, code, and instructions required to install and run a specific program on your computer.

    A Linux package contains everything a software application needs to work correctly, including the program itself, configuration files, and any dependencies (other software components it relies on). This packaging makes it easy for the package manager to handle the installation and management of software, simplifying the process of adding or removing programs from your Linux system.

What are the 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, we have apt-get, aptitude command line-based package managers.

There are several package managers used in various Linux distributions, and each has its characteristics and commands. Here are some of the most commonly used package managers in Linux:

  1. APT (Advanced Package Tool): Used primarily in Debian-based distributions like Debian, Ubuntu, Linux Mint, and others. APT uses .deb packages.

  2. DNF (Dandified Yum): Used in Fedora, Red Hat Enterprise Linux (RHEL), CentOS, and other RPM-based distributions. DNF is an improved version of the YUM package manager and uses .rpm packages.

  3. Pacman: The package manager for Arch Linux and its derivatives. It uses .pkg.tar.xz packages.

  4. Zypper: Used in openSUSE and SUSE Linux Enterprise. It works with .rpm packages.

Different commands of Package Manager

  • To install packages on the system

    sudo yum install docker.io # for linux

    sudo apt install docker.io #for ubuntu

  • To update installed packages

    sudo apt-get update

  • To remove a package

    sudo apt purge package_name

  • Systemctl and Systemd

    systemctl is a command-line utility in Linux operating systems that is used to control and manage the system’s services, daemons, and other processes. It is an essential tool for system administrators and developers as it allows them to monitor and control various system processes.

  • Systemd is a service management tool in Linux used to manage or control installed applications and services. It is a replacement of sysvinit process.

Installing Docker using package manager on Ubuntu

Following are the steps for installation of docker -

  1. Update the package lists using "update": sudo apt update

  2. Install the Docker repository using "install": sudo apt-get install docker.io -y

  3. Check the version of the docker using "version": docker version

  4. Check the status of the docker using "status": systemctl status docker

  5. Start the Docker service using "start": systemctl start docker

  6. Stop the Docker service using "stop": systemctl stop docker

  7. Uninstall docker service using "purge": sudo apt purge docker.io -y

  • Installing Jenkins using package manager on Ubuntu

Following are the steps for installation of Jenkins -

  • Jenkins requires Java to run, so update the Debian apt repositories: sudo apt update, install OpenJDK 17: sudo apt install openjdk-17-jre, and check the installation with the commands: java -version

  • Import all the Jenkins packages from the curl command:

    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

  • Update the package: sudo apt-get update

  • Install Jenkins: sudo apt-get install jenkins -y

  • Check the status of Jenkins using "status": systemctl status jenkins

  • Stop the Jenkins using "stop": systemctl stop jenkins

  • systemctl and service

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

    systemctl:

    • systemctl is a more modern and powerful service management utility introduced with systemd, which is the default init system in many modern Linux distributions. It provides extensive features for controlling services, including starting, stopping, restarting, enabling, disabling and checking the status of services.

    • Example: systemctl status docker

      service:

      • service is a legacy command used in init-based systems (SysVinit) to manage services. It is still available in many Linux distributions for backward compatibility but is being phased out in favor of systemctl. It provides a simpler interface for starting, stopping, and restarting services, but it has fewer features compared to systemctl.

      • Example: service docker status

        Hence, as seen above the outputs are same for both the commands - systemctl and service which shows both are used for managing system services but differ due to their functionalities and association with different init systems.

Thank You!

~Shilpi