๐”ป๐•’๐•ช ๐ŸŸ: "๐•Œ๐•Ÿ๐•๐• ๐•”๐•œ๐•š๐•Ÿ๐•˜ ๐•ƒ๐•š๐•Ÿ๐•ฆ๐•ฉ โ„™๐•’๐•”๐•œ๐•’๐•˜๐•– ๐•„๐•’๐•Ÿ๐•’๐•˜๐•–๐•ž๐•–๐•Ÿ๐•ฅ ๐•’๐•Ÿ๐•• ๐•Š๐•ช๐•ค๐•ฅ๐•–๐•ž๐•”๐•ฅ๐•: ๐”ธ โ„‚๐• ๐•ž๐•ก๐•ฃ๐•–๐•™๐•–๐•Ÿ๐•ค๐•š๐•ง๐•– ๐”พ๐•ฆ๐•š๐••๐•–"

๐”ป๐•’๐•ช ๐ŸŸ: "๐•Œ๐•Ÿ๐•๐• ๐•”๐•œ๐•š๐•Ÿ๐•˜ ๐•ƒ๐•š๐•Ÿ๐•ฆ๐•ฉ โ„™๐•’๐•”๐•œ๐•’๐•˜๐•– ๐•„๐•’๐•Ÿ๐•’๐•˜๐•–๐•ž๐•–๐•Ÿ๐•ฅ ๐•’๐•Ÿ๐•• ๐•Š๐•ช๐•ค๐•ฅ๐•–๐•ž๐•”๐•ฅ๐•: ๐”ธ โ„‚๐• ๐•ž๐•ก๐•ฃ๐•–๐•™๐•–๐•Ÿ๐•ค๐•š๐•ง๐•– ๐”พ๐•ฆ๐•š๐••๐•–"

ยท

10 min read

Table of contents

๐’ฒ๐’ฝ๐’ถ๐“‰ ๐’พ๐“ˆ ๐’ซ๐’ถ๐’ธ๐“€๐’ถ๐‘”๐‘’ ๐‘€๐’ถ๐“ƒ๐’ถ๐‘”๐‘’๐“‚๐‘’๐“ƒ๐“‰?

Package management in Linux refers to the process of installing, updating, configuring, and removing software packages on a Linux-based operating system. It's a fundamental component of maintaining a Linux system and ensuring that the software installed on it is up-to-date, secure, and well-integrated.

Everything related to the management of those packages is called Package Management

๐““๐“ฒ๐“ฏ๐“ฏ๐“ฎ๐“ป๐“ฎ๐“ท๐“ฝ ๐“ฃ๐”‚๐“น๐“ฎ๐“ผ ๐“ธ๐“ฏ ๐“Ÿ๐“ช๐“ฌ๐“ด๐“ช๐“ฐ๐“ฎ ๐“œ๐“ช๐“ท๐“ช๐“ฐ๐“ฎ๐“ถ๐“ฎ๐“ท๐“ฝ ๐“ฃ๐“ธ๐“ธ๐“ต๐“ผ

Different Linux system comes with different package management tools such as YUM/DNF, RPM, APT, Flatpak, Snap etc

But, Today we will learn about YUM/DNF, RPM and APT Package Managers

๐“จ๐“ค๐“œ/๐““๐“๐“• ๐“Ÿ๐“ช๐“ฌ๐“ด๐“ช๐“ฐ๐“ฎ ๐“œ๐“ช๐“ท๐“ช๐“ฐ๐“ฎ๐“ป

Yum (Yellowdog Updater, Modified) is a package manager used in Red Hat-based Linux distributions like Red Hat Enterprise Linux (RHEL), CentOS, and Fedora. It simplifies the installation, updating, and removal of software packages. Yum automatically handles dependencies and connects to software repositories to fetch and manage packages. It's a command-line tool that makes software management more efficient in these Linux distributions.

  • YUM is a primary package Management Tool for Redhat

  • YUM performs dependency resolution when installing, updating and removing software packages

  • YUM can manage packages from installed repositories in the system or from .rpm packages.

๐“—๐“ธ๐”€ ๐“ฝ๐“ธ ๐“พ๐“ผ๐“ฎ ๐“จ๐“ค๐“œ ๐“ฒ๐“ท ๐“›๐“ฒ๐“ท๐“พ๐”?

We will look at some of the commands with the YUM package manager. commands such as install, remove, upgrade etc.

  • How to install a package using YUM
yum install nginx -y
  • How to remove the package using YUM

  •   yum remove nginx
    
  • How to update a package using YUM

  •   yum update nginx
    

    Since we have installed nginx just now, it is a fresh update therefore we cannot see any updates there, but if you're version of nginx is old then you can easily update it with the update command.

    • How to upgrade a package using YUM

        yum upgrade nginx
      

      The same goes for the upgrade part. It is the latest version we have just now installed therefore there are now current upgrades available.

๐““๐“ฒ๐“ฏ๐“ฏ๐“ฎ๐“ป๐“ฎ๐“ท๐“ฌ๐“ฎ ๐“ซ๐“ฎ๐“ฝ๐”€๐“ฎ๐“ฎ๐“ท ๐“จ๐“ค๐“œ ๐“ค๐“Ÿ๐““๐“๐“ฃ๐“” & ๐“จ๐“ค๐“œ ๐“ค๐“Ÿ๐“–๐“ก๐“๐““๐“”?

Update: It will keep the old packages, so we can roll back to the previous one if the new one has issues.

Upgrade: It will delete the old packages and will install the latest version.

How to check all the options of the YUM?

yum -options

There are many more commands available further below.

The packages listed above can be updated to the latest version using the update command.

How to check history using YUM

yum check-update

We use the history command to check all the past work that has been done related to the packages history command will show you the activity with the date and time.

Undo/Redo with YUM

yum history undo/redo <id>

here, undo is also works for rollback to the previous update

This will undo the process of installing Nginx

Tips

if you're using you're system as a normal user then you will have to use sudo commands before the yum commands.

If you're using it as a root user then you can directly use the commands without using the sudo command.

RPM Package Manager

The RPM Package Manager, often referred to as RPM, is a package management system for Linux-based operating systems. It is primarily used in Red Hat, CentOS, Fedora, and other related distributions. RPM is responsible for:

  1. Packaging: It creates software packages in the RPM format, which contain the software, metadata, and installation scripts.

  2. Installation: RPM installs software packages on your system, managing dependencies to ensure that all required components are in place.

  3. Querying: It allows users to query the system for installed packages, verifying package information and version details.

  4. Updates: RPM can update software packages by replacing older versions with newer ones.

  5. Removal: It removes packages from the system cleanly, making sure to address any dependencies affected by the removal.

  • RPM Package Manager is also called RedHat package manager.

  • using RPM you can install, uninstall and query individual software packages.

  • RPM maintains a database of installed packages that enable powerful and fast queries.

Limitation of RPM

  • RPM cannot manage dependencies like the YUM package manager.

How to use RPM

  • How to install a package using RPM
rpm -i package-name
  • -i is used to install a package

To install an RPM file first you have to download a .rpm file from the web which you can easily do with the wget magic trick๐Ÿช„

Once you see that the file is downloaded then you can use the rpm commands to install the .rpm file

You can now see that the file is installed without any issue with the rpm package manager.

  • How to upgrade a package in RPM
rpm -U package-name
  • here, capital -U is used to upgrade an RPM package manager

You can see that the package we have installed is the most up-to-date package and that's why it has no pending upgrades.

Another way to install with RPM and show the progress bar

rpm -ivh package-name
  • -i stands for install

  • -v stands for verbose

  • -h is used to show the hash rate (progress bar)

How to delete a file using RPM

rpm -evh package-name
  • -e stands for erase (remove/uninstall)

  • -v stands for verbose

  • -h stands for the hash rate (progress bar)

Few more RPM commands

  • To query all the installed packages
rpm -qa

  • To get more info about the package using RPM
rpm -qi package-name

  • How to get info about a config file for a package
rpm -qc package-name

DNF Package Manager

DNF (Dandified YUM) is a modern package manager primarily used in Red Hat-based Linux distributions like Fedora and CentOS. It serves as a command-line tool for installing, updating, and managing software packages on these systems. dnf is an improved and more user-friendly replacement for the older Yum package manager.

Some dnf commands:

  • How to list all the available packages in dnf
sudo dnf list available

  • How to list all the installed packages in dnf
sudo dnf list installed

  • How to update a package using dnf
sudo dnf update

  • How to upgrade a package using dnf
sudo dnf upgrade

  • How to install a package using dnf
sudo dnf install package-name

  • How to remove a package using dnf
sudo dnf remove package-name

  • How to get info about a package
sudo dnf info package-name

  • How to search a package using dnf
sudo dnf search package

Moving ahead, let's see about the APT package manager.

APT Package Manager

APT (Advanced Package Tool) is a package management system used in Debian-based Linux distributions, such as Debian and Ubuntu. It simplifies the installation, updating, and removal of software packages. APT manages a vast repository of pre-compiled software packages, making it easy for users to access and maintain their systems with a few simple commands. It handles dependencies, ensuring that all required components for a particular software package are installed. APT is known for its reliability, and it is often used through commands like apt-get and apt.

  • APT is also known as the Advance Packaging Tool.

  • APT is very similar to YUM commands.

  • APT is generally used for Debian systems like Ubuntu, Kali Linux etc.

Some APT Commands:

  • How to install a package using apt
apt install package-name
apt-get install package-name

Since I'm using Ubuntu as my main system and Ubuntu is Debian-based system that is why it uses apt package manager and it's amazing. To see what I have installed see below.

Isn't this cool ๐Ÿ˜Ž you can do many more things like this with the apt package manager.

  • How to remove a package using apt
apt remove package-name

  • How to remove dependencies of a removed package
apt autoremove

  • How to update the repository
apt update

  • How to search for an app in the cache
apt-cache search package-name

Practical Tasks:

  1. How to install Docker on the system using the package manager?

What is Docker?

Docker is a platform for developing, shipping and running applications in containers. Containers are lightweight, isolated environments that package an application and its dependencies, making it easy to deploy and run the same software consistently across different environments. Docker simplifies software development, testing, and deployment by providing a standardized way to package and manage applications.

To perform this task we will use the apt package manager. Since I'm using Ubuntu 23.10. The APT package manager is my default package manager.

  1. Set up Docker's apt repository.
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add the repository to Apt sources:
echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

To install docker on your system you can use the following commands. These are not just some random commands but are from Docker's official website.

  1. Install the Docker packages.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

  1. Verify that the Docker Engine installation is successful by running the hello-world image.
sudo docker run hello-world

If you see this output, then you have successfully installed and started the Docker engine.

  1. How to install Jenkins on the system using the package manager?

Jenkins is like a digital assistant for software developers. It helps them build and release their software more easily. Think of it as a robot that can automatically do repetitive tasks, like testing the code and sending it to the server when it's ready. This saves time and makes sure everything works smoothly in the software development process.

To install Jenkins on our system will do:

  1. Check if you already have JAVA installed on your system

  1. Start by importing the GPG key. The GPG key verifies package integrity but there is no output
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
  https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key

  1. Add the Jenkins software repository to the source list and provide the authentication key:
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
  1. Update Your System

sudo apt-get update

  1. Install Jenkins
sudo apt-get install jenkins

As you can see above, Jenkins has been successfully installed on our system.

What is Systemctl?

Systemctl is a command in Linux used to manage system services. It allows you to start, stop, restart, enable, disable, and check the status of services, making it a crucial tool for controlling and monitoring system processes and daemons.

What is Systemd?

Systemd is a system and service manager in Linux that handles the startup, management, and control of system processes and services. It's a replacement for the traditional System V init system and provides features like parallel startup, service dependencies, logging, and more.

Some commands of Systemctl:

  1. systemctl start service-name: Start a specific service.

  2. systemctl stop service-name: Stop a specific service.

  3. systemctl restart service-name: Restart a specific service.

  4. systemctl status service-name: Check the status of a service.

  5. systemctl enable service-name: Enable a service to start at boot.

  6. systemctl disable service-name: Disable a service from starting at boot.

  7. systemctl list-units --type=service: List all active services.

  8. systemctl list-unit-files --type=service: List all available services.

Note: To enable all these services you need to have admin rights.

Systemctl Tasks:

  1. check the status of the Docker Service in your system
systemctl status docker

  1. stop the service, Jenkins

you can see that the jenkins service is active on our system and now let's stop the Jenkins service

systemctl stop jenkins
systemctl status jenkins

Congratulations ๐ŸŽ‰ you have now understood the concepts of package manager and systemctl commands in Linux. You have also learned how to start and stop a service and also how to check the status of that service.

Summary

Explains package management in Linux, specifically focusing on YUM/DNF, RPM, APT, and DNF package managers. It covers the basics of each package manager, including installation, removal, updates, and other common commands. The text also briefly introduces Docker and Jenkins installation processes and provides practical examples of using systemctl to manage system services.

In summary, package management is essential for installing, updating, and removing software packages in Linux. Various package managers like YUM/DNF, RPM, APT, and DNF are available, each with its own set of commands and functionalities. The text also introduces systemctl as a tool for managing system services.

ย