3. Package management

3.1. Outline

  • Debian and Ubuntu packages.

  • Advanced Package Tool (APT) for package installation, removal, search, and query.

  • Debian package tool (dpkg) for package installation, removal, and query.

  • Redhat packages.

  • Yellowdog Updater Modified (YUM and DNF) for package installation, removal, search, and query.

  • Redhat Package Manager (RPM) for package installation, removal, and query


3.2. The purpose of Linux packages

All files in Linux distros come in packages. Packages are used for the following tasks:

  • Install software

  • Remove software

  • Update installed software

  • Fix broken or partly removed software files

  • Reconfigure installed software


3.3. Linux package management

Linux package managemen


3.4. Ubuntu (Debian) packages

Ubuntu OS components and most of the GNU software are available in form of packages. A package file contains:

  • Software

  • Info (control) file

  • Scripts (pre/post install/remove)

  • md5sum file hashes

  • Naming convention:

(package-name)_(source version)-(package-version)_(architecture).deb

For example:

make_4.2.1-1.2_amd64.deb

Package name is make. The source version is 4.2.1 of GNU Make 4.2.1 series, package version (revision): 1.2, architecture: amd64.

The official Ubuntu distribution located in the Ubuntu archive, folder main and Restricted. In folder Restricted, there are packages with restricted vendor licensing, for example, nvidia-361.

Universe Is free software available from the network, but not officialy maintained by Ubuntu development team. For example, a2ps (“Anything to PS”), xemacs21. No guarantee of security fixes and support.

Multiverse Packages in the archive have some onerous license condition restricting use or redistribution of the software. For example, dvd-slideshow.

Developers may offer their own package repositories, called package personal archives (PPA).

You can run synaptic package manager to see what package belongs to what folder:

sudo -s
synaptic

Click on Origin to see the folders in the top left window and their packages in the top right one.


3.5. Installing Ubuntu packages with APT (Exercises)

Clone kvm1 into kvm3:

virsh shutdown kvm1
virt-clone -o kvm1 -n kvm3 -f /home/hostadm/KVM/kvm3.qcow2

Start kvm3 VM and login to its console via virsh:

virsh start kvm3
virsh console kvm3

Fix the hostname by editing file /etc/hostname with nano editor:

sudo -s
nano /etc/hostname

change kvm1 for kvm3.

Run script

vm_id_reset.sh

Reboot the VM:

reboot

Login to kvm3.

Try executing command make, which doesn’t exist on the VM yet:

make

The system error comes: The program ‘make’ is currently not installed.

You can install it by typing: sudo apt-get install make Install recommended package make by running apt-get install:

apt-get install make

You should be able to run command make now.

Simulate package installation by using option -s:

apt-get install -s netpbm

Notice the prerequisite library package that would get installed, libnetpbm10 Download the package without installation:

apt-get install -d netpbm

Notice the deb files with the packages in the apt cache directory:

ls -l /var/cache/apt/archives

Another way to download a package and get it in the current working directory:

apt-get download netpbm

Install the package:

apt-get install netpbm

Updating all the installed packages

apt-get update
apt-get upgrade

The APT repository and software folders are defined in file /etc/apt/sources.list and optionally in directory /etc/apt/sources.list.d


3.6. Removing Ubuntu packages with APT (Exercises)

Remove package make by running apt-get remove:

apt-get remove make

Simulate package removal by using option -s:

apt-get remove -s netpbm

Notice package libnetpbm10 won’t be removed Simulate package removal with the dependencies:

apt-get autoremove -s netpbm

Notice the both packages would be removed. Remove the package with the dependencies:

apt-get autoremove netpbm

Both netpbm and libnetpbm10 should be gone now.


3.7. Search and quiry Ubuntu packages with APT (Exercises)

First, update the available package list from the Ubuntu repository:

apt-get update

Search for packages containing string make in their name or description:

apt-cache search make

Narrow down the search results for the names containing make:

apt-cache search --names-only make

Filter the output for word make

apt-cache search --names-only make | grep -w ^make

Get the information about package make:

apt-cache show make

List the packages that depend on package make. Forcefully removing make would break these packages.

apt-cache showpkg make

Show the packages a given package depends on:

apt-cache depends make

3.8. Quiry Ubuntu packages with dpkg (Exercises)

What packages are installed on the system?

dpkg -l

Quiry package status with dpkg:

dpkg -s make
dpkg -s tzdata

List the files contained in the package:

dpkg -L tzdata

What package contains a file? For example, command /bin/ls

dpkg -S /bin/ls

Reconfigure a package with command dpkg-reconfigure after installation:

dpkg-reconfigure tzdata

To see the current package configuration, command debconf-show can be used, for example:

debconf-show tzdata

If there is no package dependencies, then a package can be installed with command dpkg. Otherwise, use APT. Install package make:

cp /var/cache/apt/archives/make_4.2.1-1.2_amd64.deb /tmp
cd /tmp
dpkg -i make_4.2.1-1.2_amd64.deb

To see the list of the files, contained in the deb package file:

dpkg --contents make_4.2.1-1.2_amd64.deb

Remove package make by using command dpkg:

dpkg --purge make

3.9. RedHat packages

RPM Package naming convention:

(package-name)-(source version)-(package release).(architecture).rpm

For example,

nano-2.9.8-1.el8.x86_64.rpm

Package name is nano. The source version is 2.9.8. The package release is 1.el8 (Release 1 for RedHat Enterprise Linux 8). Architecture is x86_64.


3.10. Installing and removing RedHat packages with DNF (Exercises)

Start your rocky8 VM, login to its console via command virsh console:

virsh start rocky8
virsh console rocky8

Clean the dnf cache:

dnf clean all

Install package netpbm on it:

dnf install netpbm

Reinstall package netpbm:

dnf reinstall netpbm

You can download packages without installation, for example:

dnf download make
ls -l make*

Check available updates for installed packages:

dnf check-update

Update package tzdata

dnf update tzdata

Updating all the installed packages:

dnf update

To remove an installed package:

dnf remove netpbm

The same can be accomplished with:

dnf erase netpbm

The dnf configuration is stored in file /etc/dnf/dnf.conf The dnf repositores are defined in directory /etc/yum.repos.d/*.repo


3.11. Search and quiry RPM packages with DNF (Exercises)

List the installed package and the package available for installation

dnf list make
dnf list gsl

The former package showes up as installed and the latter as available for installation.

Search for packages containing string make in their name or description:

dnf search make

Get the information about package make:

dnf info make

List the packages that package make depends upon:

dnf deplist make

The detailed info on dnf can be found in the man pages:

man dnf

3.12. Query RPM packages with rpm (Exercises)

What packages are installed on the system?

rpm -qa

A friendly readable list comes after sorting the output:

rpm -qa | sort | less

Quiry package status with rpm:

rpm -q make

Display information about the installed package:

rpm -qi make

List the files contained in the package:

rpm -ql make

Which package owns a file? For example, command /bin/ls

rpm -qf /bin/ls

RPM dependencies:

rpm -qR make

If there is no package dependencies or the dependencies have already been resolved, then a package can be simply installed with command rpm from its file. Otherwise, use DNF. Install package make from its rpm file:

rpm -ivh make-4.2.1-11.el8.x86_64.rpm

It says the package is already installed. Try to remove package make by using command rpm:

rpm -e make

It won’t go because openssl package depends on it.

Quiry a package file, for example:

rpm -qp make-4.2.1-11.el8.x86_64.rpm
rpm -qlp make-4.2.1-11.el8.x86_64.rpm
rpm -qip make-4.2.1-11.el8.x86_64.rpm

The second command above shows the files contained in the package file, and the third command displays the info about the package. More info about command rpm can be found in the man pages:

man rpm