Understanding package manager and systemctl

Vanshika SharmaVanshika Sharma
6 min read

What is a package manager in Linux?

A package manager in Linux is like your personal app store and librarian rolled into one. It helps you install, update, and manage software on your system by keeping track of all your software and ensuring everything's up-to-date and compatible. Examples include apt for Debian-based systems like Ubuntu, yum or dnf for Fedora, and pacman for Arch Linux. This way, you're not sifting through endless websites and files—your package manager does the heavy lifting.

What is a package?

In Linux, packages are the building blocks that make up your software environment. When you install a package using a package manager, it unpacks and installs the software on your system, ensuring all the pieces fit together perfectly. This streamlined process prevents the headaches of missing files or incompatible versions.

Key Components of a Package:

  1. Executable files: The actual software or program to be run.

  2. Configuration files: Pre-set configurations or options for the software.

  3. Dependencies: The software needs information about other packages or libraries to function properly.

  4. Metadata: Information about the package such as the name, version, maintainer, and description of the software.

  5. Scripts: Instructions for the package manager to follow before and after the package installation, like post-installation setup.

Types of Packages:

  1. Binary packages: These contain pre-compiled software that is ready to install and run. Examples include .deb files for Debian-based systems (like Ubuntu) or .rpm files for Red Hat-based systems (like Fedora).

  2. Source packages: Source packages contain the source code of the software and are compiled into binaries during installation, allowing for customization and optimization. Gentoo's Portage system is an example of a source-based package manager.

Different kinds of package managers

APT: For Debian-based distributions like Ubuntu. Apt handles software installation and removal, ensuring all dependencies are met.

YUM/DNF: Used by Fedora, CentOS, and RHEL. DNF is the next-generation version of YUM, offering better performance and more features.

Pacman: The go-to for Arch Linux. It keeps things simple, reflecting Arch's philosophy.

Zypper: Found in openSUSE, Zypper offers powerful features and easy handling of repositories.

Each of these caters to different Linux distributions and their specific needs. They all make your life easier by managing your software seamlessly.

Installing docker and Jenkins using package managers on Ubuntu and CentOS

Ubuntu:

Install Docker:

  1. Update your package list:

     sudo apt update
    
  2. Install Docker:

     sudo apt install docker-ce docker-ce-cli containerd.io
    
  3. Verify the installation:

     sudo docker run hello-world
    

Install Jenkins:

  1. Add the Jenkins repository:

     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
    
  2. Update your package list:

     sudo apt update
    
  3. Install Jenkins:

     sudo apt install jenkins
    
  4. Verify the installation:

     sudo systemctl status jenkins
    

CentOS:

Install Docker:

  1. Add the Docker repository:

     sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    
  2. Install Docker:

     sudo dnf install docker-ce docker-ce-cli containerd.io
    
  3. Start Docker:

     sudo systemctl start docker
     sudo systemctl enable docker
    
  4. Verify the installation:

     sudo docker run hello-world
    

Install Jenkins:

  1. Install Java (Jenkins requires Java):

     sudo dnf install java-1.8.0-openjdk-devel
    
  2. Add the Jenkins repository:

     sudo rpm -Uvh https://pkg.jenkins.io/redhat-stable/jenkins.repo
    
  3. Update your package list:

     sudo dnf update
    
  4. Install Jenkins:

     sudo dnf install jenkins
    
  5. Start Jenkins:

     sudo systemctl start jenkins
     sudo systemctl enable jenkins
    
  6. Verify the installation:

     sudo systemctl status jenkins
    

systemctl and systems

systemd is a system and service manager for Linux operating systems. It provides a consistent way to manage system processes and daemons across different distributions and is responsible for initializing the system and managing everything that starts up after the kernel.

systemctl is a command-line utility that interacts with systemd. It allows you to manage and control the systemd system and services.

Here are some key systemctl commands:

  • Start a service: sudo systemctl start [service_name]

  • Stop a service: sudo systemctl stop [service_name]

  • Enable a service to start at boot: sudo systemctl enable [service_name]

  • Disable a service: sudo systemctl disable [service_name]

  • Check the status of a service: sudo systemctl status [service_name]

  • Reload systemd manager configuration: sudo systemctl daemon-reload

Checking the status of the docker service in a system

To check the status of the Docker service on your system, you can follow these steps:

1. Open a terminal.

2. Run the following command:

sudo systemctl status docker

3. Interpret the output:

  • If Docker is running, you will see something like this:

      ● docker.service - Docker Application Container Engine
         Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
         Active: active (running) since [date]; [time]
         Docs: https://docs.docker.com
    
  • If Docker is not running, you'll see an "inactive" or "failed" status. In that case, you can start the Docker service using:

      sudo systemctl start docker
    

Stop the service, Jenkins:

Steps to Stop the Jenkins Service and Verify:

  1. Open the terminal.

  2. Check the current status of the Jenkins service:

     sudo systemctl status jenkins
    

    This will show whether Jenkins is running.

  3. Stop the Jenkins service:

     sudo systemctl stop jenkins
    
  4. Check the status again to confirm that Jenkins has stopped:

     sudo systemctl status jenkins
    

Both systemctl and service are used to manage system services on Linux, but they have different usage contexts. systemctl is part of the systemd system manager, while service is older and works with SysV-style init systems. Here's a comparison and explanation of both:

systemctl vs service

1. systemctl (for systemd-based systems)

  • Introduced with systemd, the modern system and service manager for Linux distributions.

  • Used in: Most modern distributions (like Ubuntu 15.04+, CentOS 7+, Debian 8+, Fedora, etc.) that have adopted systemd.

  • Syntax:

      sudo systemctl [action] [service_name]
    

Common Commands with systemctl:

  • Start a service:

      sudo systemctl start service_name
    
  • Stop a service:

      sudo systemctl stop service_name
    
  • Restart a service:

      sudo systemctl restart service_name
    
  • Reload a service's configuration (without restarting):

      sudo systemctl reload service_name
    
  • Check the status of a service:

      sudo systemctl status service_name
    
  • Enable a service to start at boot:

      sudo systemctl enable service_name
    
  • Disable a service from starting at boot:

      sudo systemctl disable service_name
    

2. service (for older SysVinit-based systems)

  • Used in: Older Linux distributions (like Ubuntu before 15.04, CentOS 6 and earlier, Debian 7 and earlier) or systems that still use SysVinit or Upstart.

  • Syntax:

      sudo service [service_name] [action]
    

Common Commands with service:

  • Start a service:

      sudo service service_name start
    
  • Stop a service:

      sudo service service_name stop
    
  • Restart a service:

      sudo service service_name restart
    
  • Reload a service's configuration:

      sudo service service_name reload
    
  • Check the status of a service:

      sudo service service_name status
    

Example:

To check the status of the nginx service:

  • Using systemctl:

      sudo systemctl status nginx
    
  • Using service:

      sudo service nginx status
    
2
Subscribe to my newsletter

Read articles from Vanshika Sharma directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Vanshika Sharma
Vanshika Sharma

I am currently a B.Tech student pursuing Computer Science with a specialization in Data Science at I.T.S Engineering College. I am always excited to learn and explore new things to increase my knowledge. I have good knowledge of programming languages such as C, Python, Java, and web development.