Understanding package manager and systemctl

Understanding package manager and systemctl

What is a package manager in Linux?

A package manager in Linux is a software tool that simplifies the process of installing, upgrading, configuring, and managing software packages on a Linux system. It provides a centralized repository of software packages and handles dependencies to ensure that everything is installed correctly and works together seamlessly.


What is a package?

A package is a collection of files and software components that are bundled together for easy installation, management, and distribution. In the context of Linux, a package usually contains a software application along with its dependencies, configuration files, and other necessary resources required for the software to function properly. A package allows for easy installation, upgrading, and removal of software components and simplifies the process of managing and distributing software across different Linux systems.


Different kinds of package managers?

  1. dpkg - This is the package manager used by Debian-based systems such as Debian and Ubuntu.

  2. apt-get - This is a command-line tool used with dpkg to install, upgrade, and manage packages in Debian-based systems.

  3. yum - This is the package manager used by Red Hat-based systems such as Red Hat, CentOS, and Fedora.

  4. dnf - This is the successor to yum, used in newer versions of Fedora and Red Hat-based systems.

  5. pacman - This is the package manager used by Arch Linux.

  6. Zypper - This is the package manager used by openSUSE.

  7. Portage - This is the package manager used by Gentoo Linux.

  8. emerge - This is a command-line tool used with Portage to install, upgrade, and manage packages in Gentoo Linux.


Some example of yum command

  1. Installing a package: yum install <package name> This command installs the specified package along with its dependencies.

  2. Updating packages: yum update This command updates all installed packages to their latest versions.

  3. Removing a package: yum remove <package name> This command removes the specified package along with its dependencies.

  4. Searching for a package: yum search <package name> This command searches the repository for packages matching the specified search term.

  5. Checking for package information: yum info <package name> This command displays information about the specified package, including its version, description, and dependencies.

  6. Listing installed packages: yum list installed This command lists all the packages that are currently installed on the system.

  7. Cleaning up the cache: yum clean all This command cleans up the Yum cache, removing any cached packages and metadata that are no longer needed.

These are just a few examples of the many commands that can be used with Yum. For more information on Yum commands, you can refer to the Yum documentation or use the yum --help command to see a list of available commands.


Some example of apt command

  1. sudo apt update: This command updates the local package index, allowing your system to know about the latest available packages.

  2. sudo apt upgrade: This command upgrades all the installed packages on your system to their latest available versions.

  3. sudo apt install package-name: This command installs a new package on your system.

  4. sudo apt remove package-name: This command removes an installed package from your system.

  5. sudo apt autoremove: This command removes any packages that were automatically installed as dependencies of other packages and are no longer needed.

  6. sudo apt search search-term: This command searches for a package that matches the given search term.

  7. sudo apt show package-name: This command shows detailed information about a package, including its description, dependencies, and installed size.

  8. sudo apt list --installed: This command lists all the packages that are currently installed on your system.

  9. sudo apt-cache search search-term: This command searches for a package in the APT cache and returns a list of matching packages.

These are some of the most commonly used APT commands for managing packages in Ubuntu and other Debian-based systems.


You have to install docker and jenkins in your system from your terminal using package managers

Installing Docker:

  1. Update the APT package index: sudo apt update

  2. Install the necessary packages to allow APT to use repositories over HTTPS: sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release

  3. Add Docker’s official GPG key: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

  4. Add the Docker repository to APT sources: echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

  5. Update the APT package index again: sudo apt update

  6. Install Docker: sudo apt-get install docker-ce docker-ce-cli containerd.io

  7. Check that Docker is installed and running: sudo docker run hello-world

Installing Jenkins:

  1. Add the Jenkins repository key to the system: wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -

  2. Add the Jenkins repository to APT sources: sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'

  3. Update the APT package index: sudo apt update

  4. Install Jenkins: sudo apt install jenkins

  5. Check that Jenkins is running: sudo systemctl status jenkins

That's it! You should now have Docker and Jenkins installed and running on your system.


systemctl and systemd

Systemd provides a command-line interface called systemctl, which is used to manage services and view the status of the system. Here are some of the commonly used systemctl commands:

  1. systemctl status service-name: This command shows the status of a service, including whether it is running or not.

  2. systemctl start service-name: This command starts a service.

  3. systemctl stop service-name: This command stops a service.

  4. systemctl restart service-name: This command stops and then starts a service.

  5. systemctl enable service-name: This command enables a service to start automatically at boot time.

  6. systemctl disable service-name: This command disables a service from starting automatically at boot time.

  7. systemctl daemon-reload: This command reloads systemd configuration files after changes have been made.


    check the status of docker service in your system (make sure you completed above tasks, else docker won't be installed)

To check the status of the Docker service in your system, you can use the following command:

sudo systemctl status docker

This command will display the current status of the Docker service, including whether it is running or not.

If Docker is installed and running, you should see output similar to the following:

● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2022-04-04 15:44:33 IST; 2 days ago
     Docs: https://docs.docker.com
 Main PID: 2564 (dockerd)
    Tasks: 8
   Memory: 39.5M
   CGroup: /system.slice/docker.service
           └─2564 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

If Docker is not running, you can start it using the following command:

sudo systemctl start docker

And you can check the status again to confirm that it is now running:

sudo systemctl status docker

stop the service jenkins and post before and after screenshots

To stop the Jenkins service, you can use the following command:

sudo systemctl stop jenkins

systemctl status docker vs service docker status

The commands systemctl status docker and service docker status are used to check the status of the Docker service in a Linux system, but they use different tools to do so.

systemctl is a command-line tool used to control the systemd system and service manager. systemctl status docker is used to display the current status of the Docker service using the systemd system and service manager.

On the other hand, service is a command-line tool used to manage services in Linux systems. service docker status is used to display the current status of the Docker service using the system's init system.

In most modern Linux systems, systemd is the default system and service manager, so using systemctl status docker is generally recommended. However, service docker status can still be used in some older Linux systems or in cases where systemd is not being used.