Understanding Package Management and Systemctl | Day 7 of 90 Days of DevOps

Ajit Fawade
5 min readJul 25, 2023

--

Photo by Petrebels on Unsplash

In my previous blog posts, I discussed the basics of file permissions in Linux, Linux shell scripting, and user management. In this post, I will discuss package management and systemd, two important concepts in Linux administration. Let’s demystify these concepts, explore package managers, and understand the power of Systemctl in Linux.

What is package management?

Package management is the process of installing, updating, and removing software packages on a Linux system. A package is a collection of files that make up a software application. Package managers are used to make it easy to install and manage software packages.

What is a package in Linux?

A package in Linux is a file or collection of files that make up a software application. Packages are typically compressed and archived, and they often include information about the software application, such as the name, version, and dependencies.

Some of the common tasks that you can do with a package manager are:

  • Install a new package: This will download the package from a repository (an online or offline source of packages) and install it on your system, along with any dependencies that it requires.
  • Remove an existing package: This will uninstall the package from your system and remove any files or configuration settings that it created.
  • Update an existing package: This will check if there is a newer version of the package available in the repository and upgrade it if necessary.
  • Search for a package: This will look for a package that matches a given keyword or name in the repository and display some information about it.
  • List installed packages: This will show you all the packages that are currently installed on your system and their versions.

Different kinds of package managers

There are many different package managers available for Linux. Some of the most popular package managers include:

  • APT (Advanced Packaging Tool) is the default package manager for Debian-based distributions, such as Ubuntu and Mint.
  • YUM (Yellowdog Update Manager) is the default package manager for Red Hat-based distributions, such as CentOS and Fedora.
  • DNF (Dandified YUM) is a newer package manager that is based on YUM.
  • Pacman is the default package manager for Arch Linux.

Below are some examples of using the apt package manager on Ubuntu.

To install Docker on Ubuntu using apt, you can run the following commands:

# Update the package index
sudo apt update

# Install Docker
sudo apt install docker.io

To remove Jenkins on Ubuntu using apt, you can run the following command:

# Remove Jenkins
sudo apt remove jenkins

To search for a package named nginx on Ubuntu using apt, you can run the following command:

# Search for nginx
apt search nginx

To list all the installed packages on Ubuntu using apt, you can run the following command:

# List installed packages
apt list --installed

systemd and systemctl

Systemd is the init system and service manager for most Linux distributions. It is responsible for starting and stopping system services, such as the Docker daemon and the Jenkins service.

Systemctl is a command-line tool that allows you to control and monitor the systemd system and service manager. Systemctl can be used to perform various operations on units, such as starting, stopping, restarting, reloading, enabling, disabling, masking, unmasking, checking status, and so on.

Some of the common tasks that you can do with systemctl are:

  • Start a service: This will activate a service unit and run its start-up commands.
  • Stop a service: This will deactivate a service unit and run its stop commands.
  • Restart a service: This will stop and then start a service unit.
  • Reload a service: This will reload the configuration of a service unit without stopping it.
  • Enable a service: This will make a service unit start automatically at boot time by creating a symbolic link in the appropriate directory.
  • Disable a service: This will undo the enable operation by removing the symbolic link.
  • Mask a service: This will prevent a service unit from being started manually or automatically by creating an empty file in the appropriate directory.
  • Unmask a service: This will undo the mask operation by removing the empty file.
  • Check the status of a service: This will show some information about a service unit, such as its state, PID, memory usage, logs, etc.

For example, to start Docker on Ubuntu using systemctl, you can run the following command:

# Start Docker
sudo systemctl start docker

To stop Jenkins on Ubuntu using systemctl, you can run the following command:

# Stop Jenkins
sudo systemctl stop jenkins

To check the status of Docker on Ubuntu using systemctl, you can run the following command:

# Check status of Docker
sudo systemctl status docker

Run Hello World in Docker

That’s all for today. I hope you learned something new and useful about package management and systemctl in Linux. In the coming blog posts, I will be writing about how to use Docker and Jenkins to create a continuous integration pipeline. Stay tuned! 😊

If you liked this blog post, please share it with your friends and colleagues who are also interested in DevOps. You can also follow me on LinkedIn and GitHub to see more of my work and progress.

Thank you for reading and happy learning! 🙌

--

--

No responses yet