Understanding package manager and systemctl

Understanding package manager and systemctl

Day 7 of 90daysofdevops

What is Package Manager in Linux?

  • A package manager in Linux is a software tool that automates the process of installing, upgrading, configuring, and removing software packages on a Linux system. It provides a convenient way to search for and install software from a central repository of pre-built and pre-configured software packages.

What is Package?

  • In Linux, a package refers to a collection of files that are bundled together to perform a specific function, such as a program or application. The package typically includes the executable file, any libraries or dependencies required by the program, documentation, and other supporting files.

  • Linux distributions, such as Ubuntu or Debian, use package management systems that automate the installation, removal, and updating of packages. These systems typically use a package manager (such as apt or yum) to manage the packages.

  • Packages are often distributed in a compressed format, such as .deb or .rpm files, which can be easily installed using the package manager. The package manager handles the installation process, ensuring that all dependencies are met and any necessary configuration files are created.

Different Kind of Package Manager?

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

  • There are several package managers available in Linux, and the most commonly used ones are:
  1. Advanced Packaging Tool (APT):

    APT is the default package manager used in Debian-based distributions such as Ubuntu, Linux Mint, and Debian. It manages packages by downloading them from repositories over the internet.

  2. Yellowdog Updater Modified (YUM):

    YUM is a package manager used in Red Hat-based distributions such as CentOS, Fedora, and Red Hat Enterprise Linux. It manages packages by downloading them from repositories over the internet.

  3. DNF (Dandified Packaging Tool):

    This is a package manager that installs, updates and removes packages on RPM-based Linux distributions. It is a more advanced version of the YUM manager and is intended to be the replacement for YUM in RPM-based systems.

  4. Dpkg(Debian Package Management System):

    This is a base package management system for the Debian Linux family, it is used to install, remove, store, and provide information about .deb packages.

  5. RPM (Red Hat Package Manager):

    This is the Linux Standard Base packing format and a base package management system created by RedHat.


Installation of Docker on Ubuntu

  1. To update all the packages in the system use the following command:

     sudo apt-get update
    
  2. Install Docker using the following command:

     sudo apt install docker.io -y
    
  3. Install all the dependency packages using the following command:

     #Install the snapd for Docker
     sudo apt install snapd -y
    
     sudo snap install docker
    

  4. Before testing Docker, check the version installed using the following command:

     docker --version
    

  5. To check the docker status use the following command

     sudo systemctl stop docker
    
     # CTRL + C -> To exit from prompt
    

  6. To stop a docker service

     sudo systemctl status docker
    
     # CTRL + C -> To exit from prompt
    

Installation of Jenkins on Ubuntu

  1. Installation of Java as per the prerequisite

     sudo apt-get install openjdk-11-jdk -y
    
  2. Adding the repository to the system

     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
    
  3. After both commands have been entered, run apt update so that apt will use the new repository.

     sudo apt-get update
    
  4. Finally, install Jenkins and check the status:

     sudo apt-get install jenkins
    
     sudo systemctl status jenkins
    

  5. Stopping the Jenkins

     sudo systemctl stop jenkins
    


Installation of Docker in CentOS

  1. Update Docker Package Database

     sudo yum check-update
    
  2. Install the Dependencies

     sudo yum install -y yum-utils device-mapper-persistent-data lvm2
    
  3. Add the Docker Repository to CentOS

     sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    
  4. Install Docker On CentOS Using Yum

     sudo yum install docker
    
  5. Manage Docker Service

     #Start Docker:
     sudo systemctl start docker
    
     #Enable Docker:
     sudo systemctl enable docker
    
     #Check the status of the service with:
     sudo systemctl status docker
    

systemctl & systemd

  • Systemd is a system and service manager for Linux operating systems. It is responsible for starting and stopping system services and managing system resources. Systemd was introduced as a replacement for the traditional SysVinit system initialization process and has become the standard for many modern Linux distributions.

  • Systemctl is a command-line tool that is part of the systemd suite of tools. It is used to control and manage services that are managed by systemd. With systemctl, you can start, stop, restart, enable, and disable services, as well as view the status of running services and get information about services that are installed on your system.

systemctl commands:

#Starting a Service 
sudo systemctl start <service_name>

#Stopping a Service 
sudo systemctl stop  <service_name>

#Restart a Service 
sudo systemctl restart  <service_name>

#Reload a Service
sudo systemctl reload  <service_name>

#Enabling a Services 
sudo systemctl enable  <service_name>

#Disabling a Services 
sudo systemctl disable  <service_name>

#Checking the Status
systemctl status  <service_name>

service commands:

#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 the configuration of a service
sudo service <service-name> reload

#Enable a service to start automatically at boot time
sudo service <service-name> enable

#Disable a service from starting automatically at boot time
sudo service <service-name> disable

Difference between systemctl & service

  • Systemctl is the newer command for systems that boot with systemd instead of init. Systemctl is a combination of service and chkconfig for those newer systems. If you accidentally use a service on a systemd-based system, the arguments will be swapped (ie: service httpd restart will become systemctl restart httpd). They serve the same function, but they interact with different systems.

  • "Service" is the legacy command, which normally works with classical init. Although on systems which use systemd it’s actually more of a wrapper over the actual systemd native means of managing services, namely systemctl.

You use service on init systems other than systemd. You use systemctl on systemd.

Thank You,

Abhisek Moharana