Understanding package manager and systemctl in Linux #Day 7

Understanding package manager and systemctl in Linux #Day 7

What is a Package manager?

A package manager is a software tool that helps you install, update, and remove software packages on your Linux system. It provides an easy way to manage software on your system, by handling all the dependencies and configurations for you.

How do Package Managers Work?

Package managers in Linux work by downloading software packages from a central repository. A repository is a collection of software packages that are maintained by a specific organization or community. Each package in the repository is associated with metadata that includes information about the package, such as its name, version, and dependencies.

When you use a package manager to install software, it checks the repository for the package and downloads it along with any dependencies that the software requires. The package manager then installs the software and sets up any necessary configurations.

Different Package Managers in Linux

There are several package managers available in Linux, each with their own strengths and weaknesses. Some of the most popular package managers include:

  1. APT: Advanced Package Tool (APT) is a package manager used by Debian, Ubuntu, and other Debian-based distributions.

  2. YUM: Yellowdog Updater, Modified (YUM) is a package manager used by Red Hat, CentOS, and other Red Hat-based distributions.

  3. Pacman: Pacman is a package manager used by Arch Linux and its derivatives.

  4. Zypper: Zypper is a package manager used by SUSE Linux and its derivatives.

Installing Docker in your system from your terminal using package managers.

To install Docker in your system on Ubuntu or CentOS, open your terminal and use the following commands:

Installing Docker on Ubuntu

  1. Update the apt package index:

     $sudo apt update
    
  2. Install packages to allow apt to use a repository over HTTPS:

     $sudo apt install apt-transport-https ca-certificates curl software-properties-common
    
  3. Add Docker’s official GPG key:

     $curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    
  4. Set up the stable repository:

     $sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
    
  5. Update the apt package index again:

     $sudo apt update
    
  6. Install the latest version of Docker:

     $sudo apt install docker-ce
    
  7. Check Docker installation:

     $sudo systemctl status docker
    

Installing Docker on CentOS

  1. Update the yum package index:

     $sudo yum update -y
    
  2. Install required packages:

     $sudo yum install -y yum-utils device-mapper-persistent-data lvm2
    
  3. Set up the stable repository:

     $sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    
  4. Install the latest version of Docker:

     $sudo yum install docker-ce -y
    
  5. Start Docker:

     $sudo systemctl start docker
    
  6. Enable Docker to start on boot:

     $sudo systemctl enable docker
    

Installing Jenkins in your system from your terminal using package managers.

To install Jenkins in your system on Ubuntu or CentOS, open your terminal and use the following commands:

Installing Jenkins on Ubuntu

  1. Update the apt package index:

     $sudo apt update
    
  2. Jenkins requires Java to run so, to install java:

     $sudo apt-get install openjdk-11-jdk -y
    
  3. Add the Jenkins Debian repository key:

     $curl -fsSL https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
    
  4. Add the Jenkins repository:

     $sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
    
  5. Update the apt package index again:

     $sudo apt update
    
  6. Install Jenkins:

     $sudo apt install jenkins -y
    
  7. Start the Jenkins service:

     $sudo systemctl start jenkins
    
  8. Enable Jenkins to start on boot:

     $sudo systemctl enable jenkins
    
  9. Open the firewall for Jenkins (default port 8080):

     $sudo ufw allow 8080
    
  10. Access Jenkins through a web browser athttp://your_server_ip_or_domain:8080.

Installing Jenkins on CentOS

  1. Update the yum package index:

     $sudo yum update -y
    
  2. Jenkins requires Java to run so, to install java:

     $sudo yum install java-11-openjdk-devel -y
    
  3. Add the Jenkins repository:

     $sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
     $sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
    
  4. Install Jenkins:

     $sudo yum install jenkins -y
    
  5. Start the Jenkins service:

     $sudo systemctl start jenkins
    
  6. Enable Jenkins to start on boot:

     $sudo systemctl enable jenkins
    
  7. Open the firewall for Jenkins (default port 8080):

     $sudo firewall-cmd --permanent --zone=public --add-port=8080/tcp
     $sudo firewall-cmd --reload
    
  8. Access Jenkins through a web browser athttp://your_server_ip_or_domain:8080.

What is systemd?

systemd is a system and service manager that provides a central way to manage system services and processes. It replaces the traditional init system used by most Linux distributions.

Benefits of systemd:

  • Faster boot times

  • Improved process management

  • Improved service management

  • Better logging and monitoring capabilities

  • Enhanced security features

systemd is designed to be backwards compatible with the traditional init system, so most of the commands and tools you're familiar with (such as service, chkconfig, and init) can still be used.

What is systemctl?

systemctl is a command-line tool used to control the systemd system and service manager. It allows you to manage and control various aspects of the system's services, including starting, stopping, enabling, disabling, and reloading services.

Some common commands that you can use with systemctl include:

  • systemctl start <service>: Starts a service

  • systemctl stop <service>: Stops a service

  • systemctl restart <service>: Restarts a service

  • systemctl enable <service>: Enables a service to start automatically at boot

  • systemctl disable <service>: Disables a service from starting automatically at boot

  • systemctl status <service>: Displays the status of a service

What is service command?

The service command in Linux is used to manage system services. It allows you to start, stop, restart, enable, disable, and check the status of services that are managed by the system's init system.

The basic syntax for using the service command is:

$sudo service <service-name> <action>

where <service-name> is the name of the service you want to manage and <action> is the action you want to perform on the service.

Here are some common actions that you can perform with the service command:

  • start: Starts a service

  • stop: Stops a service

  • restart: Restarts a service

  • reload: Reloads the configuration of a service

  • status: Displays the status of a service

  • enable: Enables a service to start automatically at boot

  • disable: Disables a service from starting automatically at boot

Note:servicecommand is being phased out in favor ofsystemctlandsystemdon newer Linux distributions. However, it is still supported on many systems and can be a useful tool for managing services.

The commands of systemctl vs service

Both systemctl and service are used to control services, but the systemctl is new and more powerful.

The commands to check Docker status using systemctl and service are:

systemctl:

$sudo systemctl status docker

service:

$sudo service docker status

Commands of systemctl:

  1. To start a service:
$sudo systemctl start <service_name>
  1. To stop a service:
$sudo systemctl stop <service_name>
  1. To restart a service:
$sudo systemctl restart <service_name>
  1. Check the status of a service:
$sudo systemctl status <service_name>

Commands of service:

  1. To start a service:
$sudo service <service_name> start
  1. To stop a service:
$sudo service <service_name> stop
  1. To restart a service:
$sudo service <service_name> restart
  1. Check the status of a service:
$sudo service <service_name> status

That's all from me for today! I hope you found this blog interesting. Any recommendations and improvements are most welcome! Make sure to like and follow!

Happy Learning!