Packages
Introduction
We would like to install some software on our system. One way is to look for it using a browser, download it, hope it's not a virus and then run the executable. Wouldn't it be nice if we had a mechanism that we could just tell "Hey install the Open SSH server for me." .package manager
A package manager is a tool that allows users to install, remove, upgrade, configure and manage software packages on an operating system. The package manager can be a graphical application like a software center or a command line tool like apt-get or pacman.package
Package is usually referred to an application but it could be a GUI application, command line tool or a software library (required by other software programs). A package is essentially an archive file containing the binary executable, configuration file and sometimes information about the dependencies.Sample package managers
The following list shows the names of some well-known packages in Linux: Portage Pacman pkgsrc Nix AppImage YUM yay Conda GNU Guix Docker Flatpak eopkg In the following, a short explanation about some package managers is given: rpm This the package management system used by Linux Standard Base (LSB)-compliant distributions for the low-level handling of packages. Just like dpkg, it can query, install, verify, upgrade, and remove packages, and is more frequently used by Fedora-based distributions, such as RHEL and CentOS. dpkg It is a low-level package manager for Debian-based systems. It can install, remove, provide information about and build *.deb packages but it can’t automatically download and install their corresponding dependencies. apt-get It's a high-level package manager for Debian and derivatives and provides a simple way to retrieve and install packages, including dependency resolution, from multiple sources using the command line. Unlike dpkg, apt-get does not work directly with *.deb files, but with the package proper name. yum It adds the functionality of automatic updates and packages management with dependency management to RPM-based systems. As a high-level tool, like apt-get or aptitude, yum works with repositories. aptitude It's another high-level package manager for Debian-based systems, and can be used to perform management tasks (installing, upgrading, and removing packages, also handling dependency resolution automatically) in a fast and easy way. It provides the same functionality as apt-get and additional ones, such as offering access to several versions of a package. dnf DNF, short for Dandified Packaging Tool, is a more modernized and advanced version of the YUM manager – incorporating the features of YUM while improving performance and resource usage. For now, only Fedora has utilized this next-generation version of YUM, but hopefully, we will see it spread to more operating systems in the future. pacman Pacman is the package manager found on Arch Linux. Pacman is the only package management tool found on Arch, making it not a front end. Arch Linux is a rolling release operating system, with updates, added every day. There are only a few commands with Pacman, intended for searching, installing, and removing packages. This package manager can connect to the internet and acquire its packages from there, making it more user-friendly. However, Pacman is intended for installing software from the Arch repository, rendering it unable to install from third-party repositories. portage Portage is the package manager for Gentoo, a no-frills operating system that has to be compiled from scratch when installing on any system. It is one of the most advanced package managers currently available, with new features and improvements being added continuously. up2date up2date, also known as the Red Hat Update Agent, is a tool used by older versions of Red Hat Enterprise Linux, CentOS, and Fedora Core that downloads and installs new software and upgrades the operating system. It functions as a front-end to the RPM Package Manager and adds advanced features such as automatic dependency resolution. The file /etc/sysconfig/rhn/sources specify where up2date will search for packages. abs ABS, short for Arch Build System, is a system of tools intended for creating installable software packages for Arch Linux out of source code. This consists of several tools functioning together to create packages – these tools are all independent programs, such as makepkg, pacman, asp, and so on. The package creation/installation method using ABS differs from a conventional Linux distribution. Instead of installing pre-compiled packages, you need the PKGBUILD file to be created from an Svn or Git branch by using the asp package. urpmi urpmi is a package management tool for installing, removing, updating and querying software packages of local or remote (networked) media. It wraps around the RPM Package Manager (RPM) package manager so that the user will not suffer the often-encountered[citation needed] dependency hell. It works with official sources from Mandriva or unofficial sources such as those from the Penguin Liberation Front. It has a graphical front-end: Rpmdrake. ZYpp ZYpp is another dependency resolver for the RPM package management system and is the default package manager for OpenSUSE and SUSE Linux Enterprise. ZYpp utilizes .rpm binaries, just like YUM, but is a bit faster due to being written in C++, where YUM is written in Python. ZYpp is extremely easy to use, as it includes command shortcuts which can be used in place of the full command. Nix Nix is a purely functional package management system. This means that the act of building a package does not have side effects, such as destructively updating or deleting files that may be used by other packages. Nix makes it easy for systems to use multiple versions of the same package simultaneously, and ensure that updating or removing a package can't break other packages. Furthermore, these actions are atomic, and so the system can't be left in an unstable state. This all means that behavior with Nix is very predictable, which is particularly useful in testing configurations and deploying across multiple systems. Synaptic Synaptic is a GTK+-based graphical user interface for APT (Debian). This package management system used by Debian and its derivatives. Synaptic is usually used on systems based on deb packages but can also be used on systems based on RPM packages. It can be used to install, remove and upgrade software packages and to add repositories. URPMI URPMI is Mageia command line tool for managing packages and repositories (media). It’s a powerful command-line tool which is used to automatically download and install new software packages, upgrade existing software packages, update the package list index, and to upgrade the entire Mageia system. urpmi handles dependencies automatically. Flatpak Flatpak is a software utility for software deployment, package management, and application virtualization for Linux desktop computers. It provides a sandbox environment in which users can run applications in isolation from the rest of the system. Applications using Flatpak need permission from the user to control hardware devices or access the user's files. Entropy Entropy is the default package management system for Sabayon Linux, a Gentoo derivative. What makes Entropy interesting is Sabayon utilizes binary files through Entropy, and also source code through Gentoo package management system, Portage. SNAP Snap packages are secure, isolated from each other and the host system using technologies such as AppArmor, It’s cross-platform, self-contained, allowing a developer to package the exact software their application needs. This sandboxed isolation also improves security and allows applications, and whole snap-based systems, to be rolled back should an issue occur. It has many advantages over the more traditional package formats such as .deb, .rpm, and others. Snaps use a special YAML formatted file named snapcraft.yaml. Snaps really are the future of Linux application packaging. Slackware Packages in Slackware Linux are distributed as compressed tarballs, generally using gzip or lzma compression. These tarballs can be recognized by their suffixes, .tgz or .txz. This format includes a complete filesystem layout, as well as additional scripts to be run upon installation or removal of the software. Slackware packages do not offer dependency resolution information; this is generally viewed as allowing more flexibility and control. Packages can also be built using SlackBuilds, shell scripts that compile source or repackage binary distribution packages for easy installation and removal on Slackware.
Case Study
We are going to install OpenSSH server so that remote users can log in to or out of Linux box. First we check if OpenSSH server is already installed.Check on a Debian installation. ajay@ajkumar08-PC:~$ ssh -V OpenSSH_8.4p1 Debian-5+deb11u1, OpenSSL 1.1.1n 15 Mar 2022 ajay@ajkumar08-PC:~$ /etc/init.d/ssh status ? ssh.service - OpenBSD Secure Shell server Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2023-04-09 01:17:08 PDT; 1 weeks 5 days ago Docs: man:sshd(8) man:sshd_config(5) Process: 495 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS) Main PID: 516 (sshd) Tasks: 1 (limit: 4426) Memory: 5.2M CPU: 814ms CGroup: /system.slice/ssh.service +-516 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups Warning: some journal files were not opened due to insufficient permissions. ajay@ajkumar08-PC:~$ On the hills server the command is slightly different as it is running Red Hat Linux. [amittal@hills ~]$ ssh -V OpenSSH_8.0p1, OpenSSL 1.1.1g FIPS 21 Apr 2020 [amittal@hills ~]$ systemctl status sshd ? sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset> Active: active (running) since Thu 2023-01-12 09:57:47 PST; 3 months 8 days > Docs: man:sshd(8) man:sshd_config(5) Main PID: 1295 (sshd) Tasks: 1 (limit: 75135) Memory: 21.9M CGroup: /system.slice/sshd.service +-1295 /usr/sbin/ssh To find out the redhad release version number. [amittal@hills ~]$ cat /etc/redhat-release Red Hat Enterprise Linux release 8.4 (Ootpa) [amittal@hills ~]$
If we did not have the ssh server installed then on Debian Linux we can use "apt-get". Usually a user will not have permissions to install packages and we can either use "sudo" or "su".
To update local information about packages on the remote repository. apt-get update To actually install the server. apt-get install -y ssh ajay@DESKTOP-B6328CS:~$ su root Password: root@DESKTOP-B6328CS:/home/ajay# apt-get update Get:1 http://security.debian.org/debian-security bullseye-security InRelease [48.4 kB] Hit:2 http://deb.debian.org/debian bullseye InRelease Get:3 http://deb.debian.org/debian bullseye-updates InRelease [44.1 kB] Get:4 http://security.debian.org/debian-security bullseye-security/main Sources [189 kB] Get:5 http://security.debian.org/debian-security bullseye-security/main i386 Packages [236 kB] Get:6 http://security.debian.org/debian-security bullseye-security/main Translation-en [156 kB] Get:7 http://deb.debian.org/debian bullseye-updates/main Sources.diff/Index [17.3 kB] Get:8 http://deb.debian.org/debian bullseye-updates/main i386 Packages.diff/Index [17.3 kB] Get:9 http://deb.debian.org/debian bullseye-updates/main Sources T-2023-03-25-2025.40-F-2023-03-25-2025.40.pdiff [391 B] Get:9 http://deb.debian.org/debian bullseye-updates/main Sources T-2023-03-25-2025.40-F-2023-03-25-2025.40.pdiff [391 B] Get:10 http://deb.debian.org/debian bullseye-updates/main i386 Packages T-2023-03-25-2025.40-F-2023-03-25-2025.40.pdiff [287 B] Get:10 http://deb.debian.org/debian bullseye-updates/main i386 Packages T-2023-03-25-2025.40-F-2023-03-25-2025.40.pdiff [287 B] Fetched 709 kB in 3s (210 kB/s) Reading package lists... Done Install the ssh server root@DESKTOP-B6328CS:/home/ajay# apt-get install -y ssh Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: openssh-server openssh-sftp-server runit-helper Suggested packages: molly-guard monkeysphere ssh-askpass ufw The following NEW packages will be installed: openssh-server openssh-sftp-server runit-helper ssh 0 upgraded, 4 newly installed, 0 to remove and 13 not upgraded. Need to get 740 kB of archives. After this operation, 2,204 kB of additional disk space will be used. Get:1 http://deb.debian.org/debian bullseye/main i386 openssh-sftp-server i386 1:8.4p1-5+deb11u1 [58.8 kB] Get:2 http://deb.debian.org/debian bullseye/main i386 runit-helper all 2.10.3 [7,808 B] Get:3 http://deb.debian.org/debian bullseye/main i386 openssh-server i386 1:8.4p1-5+deb11u1 [422 kB] Get:4 http://deb.debian.org/debian bullseye/main i386 ssh all 1:8.4p1-5+deb11u1 [252 kB] Fetched 740 kB in 0s (1,845 kB/s) Preconfiguring packages ... Selecting previously unselected package openssh-sftp-server. (Reading database ... 141607 files and directories currently installed.) Preparing to unpack .../openssh-sftp-server_1%3a8.4p1-5+deb11u1_i386.deb ... Unpacking openssh-sftp-server (1:8.4p1-5+deb11u1) ... Selecting previously unselected package runit-helper. Preparing to unpack .../runit-helper_2.10.3_all.deb ... Unpacking runit-helper (2.10.3) ... Selecting previously unselected package openssh-server. Preparing to unpack .../openssh-server_1%3a8.4p1-5+deb11u1_i386.deb ... Unpacking openssh-server (1:8.4p1-5+deb11u1) ... Selecting previously unselected package ssh. Preparing to unpack .../ssh_1%3a8.4p1-5+deb11u1_all.deb ... Unpacking ssh (1:8.4p1-5+deb11u1) ... Setting up runit-helper (2.10.3) ... Setting up openssh-sftp-server (1:8.4p1-5+deb11u1) ... Setting up openssh-server (1:8.4p1-5+deb11u1) ... Creating config file /etc/ssh/sshd_config with new version Creating SSH2 RSA key; this may take some time ... 3072 SHA256:Cmpic20iyulL1SsP6n62Sli3IY5nJEc16inVwh2X56E root@DESKTOP-B6328CS (RSA) Creating SSH2 ECDSA key; this may take some time ... 256 SHA256:U1r0p1EG6j+J7WIL4SlzMVbZ1Z/h+94CI4DVYNEb7RI root@DESKTOP-B6328CS (ECDSA) Creating SSH2 ED25519 key; this may take some time ... 256 SHA256:PELjYD8vQpkG0Mpcr1lIgxUTcdxBcE1EwXi1kjYYMPY root@DESKTOP-B6328CS (ED25519) Created symlink /etc/systemd/system/sshd.service ? /lib/systemd/system/ssh.service. Created symlink /etc/systemd/system/multi-user.target.wants/ssh.service ? /lib/systemd/system/ssh.service. rescue-ssh.target is a disabled or a static unit, not starting it. Setting up ssh (1:8.4p1-5+deb11u1) ... Processing triggers for man-db (2.9.4-2) ... root@DESKTOP-B6328CS:/home/ajay#
How about on the hills server ? We don't have the "apt-get" package manager on the hills server.
[amittal@hills ~]$ whereis apt-get apt-get: [amittal@hills ~]$ However it does have "yum" installed. [amittal@hills ~]$ whereis yum yum: /usr/bin/yum /etc/yum /etc/yum.conf /usr/share/man/man8/yum.8.gz [amittal@hills ~]$ The relevant commands are: # yum install openssh # yum install openssh-server As expected we don't have permissions to use any package managers on the hills server. [amittal@hills ~]$ yum install openssh 2023-04-22 11:43:21,137 [ERROR] yum:317650:MainThread @logutil.py:194 - [Errno 13] Permission denied: '/var/log/rhsm/rhsm.log' - Further logging output will be written to stderr Not root, Subscription Management repositories not updated 2023-04-22 11:43:21,142 [ERROR] yum:317650:MainThread @identity.py:156 - Reload of consumer identity cert /etc/pki/consumer/cert.pem raised an exception with msg: [Errno 13] Permission denied: '/etc/pki/consumer/key.pem' Error: This command has to be run with superuser privileges (under the root user on most systems). [amittal@hills ~]$ As mentioned before we can check the status of the SSH server on the hills server using the below command. systemctl status sshd
Fixing errors
This section examines some of the issues that can be encountered when using package managers. We shall focus on "apt-get" .
root@ajkumar08-PC:/etc/apt# apt-get -y install yum E: Unable to locate package yum [closed]We got the above when trying to install "yum" on a Debian Linux installation. By default the "yum" package manager is not installed and we can install that using "apt-get". We have a configuration file for "apt-get" at "/etc/apt/sources.list" that contains entries of the form:
deb http://deb.debian.org/debian/ bullseye main deb-src http://deb.debian.org/debian/ bullseye main deb http://security.debian.org/debian-security bullseye-security main deb-src http://security.debian.org/debian-security bullseye-security main
We need to have all of the official source repositories for the particular distribution of yum and version. In this file "sources.list" the "#" signifies a comment. The "deb" means this archive contains pre-compiled binaries in ".deb" format. The next entry is the url where the package information is located. The next entry is the code name of the linux system and can be obtained with the command:
root@ajkumar08-PC:/etc/apt# lsb_release -c Codename: bullseye root@ajkumar08-PC:/etc/apt#
The last entry denotes the section of the repository. This can have the following values:
The package repository might be divided into many sub-sections: main: It contains officially supported open-source software restricted: It contains officially supported closed-source software universe: It contains open-source software maintained by the community multiverse: It contains unsupported, closed source, and patent-encumbered software
Once we have the correct entries in the "sources.list" we may still run into other issues. This can happen if some dependency package is not installed. Example:
Install the yum package apt-get -y install yum Reading package lists... Done Building dependency tree... Done Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: python-rpm : Depends: rpm-common (= 4.12.0.2+dfsg1-2) but 4.16.1.2+dfsg1-3 is to be installed E: Unable to correct problems, you have held broken packages.
To correct the above issue we need to install "rpm-common" first. We can do that with the command:
root@ajkumar08-PC:/etc/apt# apt-get -y install rpm-common root@ajkumar08-PC:/etc/apt#
We can also remove software.As an example to remove the openssh server we can use the below command for apt-get.
apt-get remove openssh server -y