Fatskills
Practice. Master. Repeat.
Study Guide: CompTIA Linux+ Certification: Governing Software
Source: https://www.fatskills.com/sat/chapter/comptia-linux-certification-governing-software

CompTIA Linux+ Certification: Governing Software

By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.

⏱️ ~34 min read

Objective 1.6 Given a scenario, build and install software
A Linux system is only as good as the software you install on it. The Linux kernel by itself is pretty boring; you need applications such as web servers, database servers, browsers, and word processing tools to actually do anything useful with your Linux system. This guide addresses the role of software on your Linux system and how you get and manage it.

First we discuss just how software is created in the age of open source and how you retrieve and compile software code. Next, we explore the ways Linux makes things easier for us by bundling prebuilt software packages to make installation and removal of applications a breeze.

Key Topics:
Working with Source Code
Packaging Applications
Using Application Containers

Working with Source Code
The “source” part of the open source world refers to the availability of the actual programming code used to create applications. While many commercial applications hide their source code from prying eyes, open source projects make their program code openly available for anyone to peruse and modify if needed. Most applications in the Linux environment are distributed as open source projects, so you're free to download, modify, compile, and run those applications on your Linux system.
While this may sound complicated, it really isn't. The following sections walk through the process of downloading, extracting, compiling, and running open source application code on your Linux system.

Downloading Source Code
Once developers are ready to release their open source applications to the world, they publish them on the Internet. Developers for most open source packages use a website to host their code and documentation, and many even provide user forums that allow customers to discuss issues and possible improvements.
While you can use a graphical browser to connect to a website and download source code, that's not always available, especially in Linux server environments. Linux provides a couple of command-line tools to help us download source code files directly from the command line.
The wget application is a command-line tool from the GNU Project that allows you to retrieve files from remote servers using FTP, FTPS, HTTP, or HTTPS. You specify the protocol, server name, and file to download using a standard URL format, where remotehost is the full hostname for the location hosting the files, and filename is the name of the source code file you wish to retrieve, including the folder path required:
wget http://remotehost/filename

Note: wget application supports lots of command-line options to help you customize the connection and download. These especially come in handy if you write scripts to automatically download files. Check out the manual pages for wget to see the different options available.
Yet another solution is the cURL application. It does the same thing as wget but supports many more protocols, such as DAP, DICT, FILE, Gopher, IMAP, LDAP, POP3, RTSP, SCP, SFTP, SMTP, and TFTP. It too uses the standard URL format for you to specify the protocol, server name, and file to download.
One nice feature of cURL is its ability to work with the secure HTTPS protocol. It will warn you if the remote website is using a self-signed certificate or if the certificate is signed by an untrusted certificate authority (CA).

Note: https://github.com. It provides a centralized location on the Internet for projects that use the Git version control system. The code for many open source projects is now posted in GitHub, even if there is already a dedicated website for the project. You can use both wget and cURL to download project code from GitHub.

Bundling Source Code Packages
Distributing the source code for applications can be a bit tricky.

Source code projects often consist of many different files:
Source code files
Header files
Library files
Documentation files

Trying to distribute a large batch of files for a project can be a challenge. Linux provides somewhat of an odd solution for that.
The tar program was originally developed for archiving files and folders to tape drives for backups (the tar name originally stood for tape archiver). These days it also comes in handy for bundling project files to distribute on the Internet.
The tar command allows you to specify multiple files, or even multiple folders of files, to bundle together into a single output file. You can then transfer the entire project bundle as a single file and extract the files and folders on a remote system. It's so versatile in what it can do that there is a long list of command-line options available, which can become somewhat imposing.

For most bundling operations, three basic option groups are commonly used for the tar command:
-cvf: Create a new tar file
-tvf: Display the contents of a tar file
-xvf: Extract the contents of a tar file

To create a new tar archive file, specify the output file name and then the list of files and folders to bundle.

List: Using the tar command to bundle files
$ tar -cvf test.tar test1.txt test2.txt test3.txt
test1.txt
test2.txt
test3.txt
drwxr-xr-x 2 rich rich 4096 Dec 5 08:33 .
drwxr-xr-x 19 rich rich 4096 Dec 5 08:28 ..
-rw-r--r-- 1 rich rich 795 Dec 5 08:19 test1.txt
-rw-r--r-- 1 rich rich 1020 Dec 5 08:19 test2.txt
-rw-r--r-- 1 rich rich 2280 Dec 5 08:20 test3.txt
-rw-r--r-- 1 rich rich 10240 Dec 5 08:33 test.tar

In the above list, test.tar is the name of the archive file you want to create. For the input files and folders, you can use wildcard characters to specify the names, or even redirect a listing of files to the tar command, making it very versatile in scripts. One of the advantages of bundling folders with tar is that it preserves the folder structure of your environment, including file and folder ownership, making it easier to extract the files and re-create the original environment.
 

Tip: .tar filename extension to identify a tar archive file. This is commonly called a tarball in Linux circles.

If you need to see what's in a tar archive file, use the -tvf option group:
$ tar -tvf test.tar
-rw-r--r-- rich/rich 795 2018-12-05 08:19 test1.txt
-rw-r--r-- rich/rich 1020 2018-12-05 08:19 test2.txt
-rw-r--r-- rich/rich 2280 2018-12-05 08:20 test3.txt

Notice that both the file ownerships and the file permissions are retained within the tar archive file. When you extract the files onto another system, they'll be assigned to the userid that matches the user number assigned to the original files.

Extracting the files and folders from a tar file is just a matter of using the -xvf option group:
$ tar -xvf test.tar
$ ls -al
drwxr-xr-x 2 rich rich 4096 Dec 5 08:38 .
drwxr-xr-x 20 rich rich 4096 Dec 5 08:38 ..
-rw-r--r-- 1 rich rich 10240 Dec 5 08:38 test.tar

The tar archive method makes bundling files for distribution easy, but it does tend to create a very large file, which can be awkward to handle. Linux developers usually compress the final tar archive file using some type of file compression utility.
In Linux there is a plethora of ways to create compressed files.


TABLE: Linux compression methods

Method Filename extension Description
bzip2 .bz2 Improvement to the gzip method that reduces file sizes
compress .Z The original Unix compress utility
gzip .gz Fast compression method that produces moderate-sized files
xz .xz Creates smaller compressed files but can be very slow



By far the most common zip utility used in Linux for tar archive files is the GNU gzip package. 

List: Compressing a tar archive file
$ gzip test.tar
drwxr-xr-x 2 rich rich 4096 Dec 5 08:53 .
drwxr-xr-x 20 rich rich 4096 Dec 5 08:39 ..
-rw-r--r-- 1 rich rich 795 Dec 5 08:19 test1.txt
-rw-r--r-- 1 rich rich 1020 Dec 5 08:19 test2.txt
-rw-r--r-- 1 rich rich 2280 Dec 5 08:20 test3.txt
-rw-r--r-- 1 rich rich 204 Dec 5 08:33 test.tar.gz

As seen in the List, gzip adds a .gz filename extension to the end of the file that's compressed.

Note: .tar.gz filename extension pair to just .tgz.

To decompress a compressed tarball and extract the original files, you have a couple of options. One option is to use a two-step approach. First use the gunzip command directly on the compressed tar file:
$ gunzip test.tar.gz
This restores the original test.tar file. Then you extract the tar file using the standard -xvf options of the tar command.

The second option is to decompress and extract the tarball file in one step by just adding the -z option to the tar command line:
$ tar -zxvf test.tgz
drwxr-xr-x 2 rich rich 4096 Dec 5 09:03 .
drwxr-xr-x 3 rich rich 4096 Dec 5 09:02 ..
-rw-r--r-- 1 rich rich 795 Dec 5 08:19 test1.txt
-rw-r--r-- 1 rich rich 1020 Dec 5 08:19 test2.txt
-rw-r--r-- 1 rich rich 2280 Dec 5 08:20 test3.txt
-rw-r--r-- 1 rich rich 204 Dec 5 09:02 test.tgz

gunzip program directly, it removes the compressed file and replaces it with the original file, but when you use the -z option with the tar command, it retains the compressed file along with decompressing and extracting the original files.

Compiling Source Code
Once you have the source code package files downloaded onto your Linux system, you'll need to compile them to create an executable file to run the application. Linux supports a wide variety of programming languages, so you'll need to know just what programming language the application was written in. Once you know that, you'll need to install a compiler for the program code. A compiler converts the source code into an executable file the Linux system can run.
The most common tool used for compiling programs in Linux is the GNU Compiler Collection (gcc). While originally created to support only the C programming language, gcc now supports an amazing array of different programming languages, such as Ada, C++, Fortran, Go, Java, Objective-C, Objective-C++, and OpenMP.

Note: gcc program by default, so most likely you'll need to install it on your Linux system. For Ubuntu, it's part of the build-essentials package, while for Rocky Linux you'll find it in the Development Tools package group.

To compile simple one-file programs, just run the gcc command-line command against the source code file to produce the executable file that you run on your system.

The -o option allows you to specify the name of the compiled output file; otherwise it defaults to the ugly a.out filename:
$ cat hello.c
#include <stdio.h>
int main() {
printf("Hello, this is my first C program!\n");
return 0;
$ gcc -o hello hello.c
$ ./hello
Hello, this is my first C program!

As mentioned earlier, most larger applications require additional header and library files besides the source code files to build the final application file. Depending on just how many source code, header, and library files are required for an application, the gcc command process can get very long and complicated. Separate library files need to be compiled in the proper order before the main program file can be compiled, creating a difficult road map to follow to generate the application.
There's a simple solution available for you to help keep track of all that. The make utility allows developers to create scripts that guide the compiling and installation process of application source code packages so that even novices can compile and install an application from source code.
Usually there are three steps involved with installing an application that uses a make script:
Run the configure utility, which analyzes your Linux system and customizes the make script to build the application for your environment.
Run the make utility by itself to build the necessary library files and executable files for the application.
Run make install as the root user account to install the application files in the appropriate locations on your system.
What makes C language programs so complicated is that they often split the application functions into separate library files. Each library file contains one or more specialized functions used in the application code.

The benefit of splitting functions into separate library files is that multiple applications that use the same functions can share the same library files. These files, called shared libraries, make it easier to distribute applications but more complicated to keep track of what library files are installed with which applications.

While not necessary for compiling the application source code, the ldd utility can come in handy if you need to track down missing library files for an application. It displays a list of the library files required for the specified application file:
$ ldd hello
linux-vdso.so.1 (0x00007fff7dff4000)
libc.so.6 => /lib64/libc.so.6 (0x00007fe154e57000)
/lib64/ld-linux-x86-64.so.2 (0x00007fe15521c000)

My simple hello application requires two external library files, the standard linux-vdso.so.1 and libc.so.6 files, which provide the ability for the printf() function to display the output. The ldd utility also shows where those files were found on the Linux system. That in itself can be helpful when troubleshooting issues with applications picking up the wrong library files.

Packaging Applications
While the tar, gcc, and make programs make it easier to distribute, compile, and install application source code, that's still somewhat of a messy process for installing new applications. For most Linux users, all they want to do is download an application and use it.
To help solve that problem, Linux distributions have created a system for bundling already compiled applications for distribution. This bundle is called a package, and it consists of all the files required to run a single application. You can then install, remove, and manage the entire application as a single package rather than as a group of disjointed files.
Tracking software packages on a Linux system is called package management. Linux implements package management by using a database to track the installed packages on the system. The package management database keeps track of not only what packages are installed but also the exact files and file locations required for each application. Determining what applications are installed on your system is as easy as querying the package management database.
As you would expect, different Linux distributions have created different package management systems for working with their package management databases.

However, over the years, two main package management systems have risen to the top and have become standards:
Debian package management
Red Hat package management

Because of their popularity, these are the two package management methods covered by the Linux+ exam, so these are the two package management methods we'll cover in detail in this guide.

Each package management system uses a different method of tracking application packages and files, but they both track similar information:
Application files: The package database tracks each individual file as well as the folder where it's located.
Library dependencies: The package database tracks what library files are required for each application and can warn you if a dependent library file is not present when you install a package.
Application version: The package database tracks version numbers of applications so that you know when an updated version of the application is available.


Installing and Managing Packages
Both the Debian and Red Hat package management systems have similar sets of tools for working with software packages in the package management system. We'll now take a look at both systems and the tools to use with them.

Debian Package Tools
As you can probably guess, the Debian package management system is mostly used on Debian-based Linux systems, such as Ubuntu. Debian bundles application files into a single DEB package file for distribution. The core tool to use for handling DEB files is the dpkg program.
The dpkg program is a command-line utility that has options to install, update, and remove DEB package files on your Linux system. The basic format for the dpkg command is as follows:
dpkg [options] action package-file
The action parameter defines the action to be taken on the file.


TABLE: The dpkg command actions

 

 

Action Description
-C Searches for broken installed packages and suggests how to fix them
--configure Reconfigures an installed package
--get-selections Displays currently installed packages
-i Installs the package
-I Displays information about an uninstalled package file
-l Lists all installed packages matching a specified pattern
-L Lists the installed files associated with a package
-p Displays information about an installed package
-P Removes an installed package, including configuration files
-r Removes an installed package but leaves the configuration files
-S Locates the package that owns the specified files



Each action has a set of options that you can use to modify the basic behavior of the action, such as to force overwriting an already installed package or ignore any dependency errors.
To use the dpkg program, you must have the DEB software package available, either from an installation DVD or by downloading the package from the Internet. Often you can find DEB versions of application packages ready for distribution on the application website, or most distributions maintain a central location for packages to download.

Note: www.debian.org/distrib/packages.

When you download a DEB package for a precompiled application, be careful that you get the correct package for your workstation processor chip. Source code files are compiled for specific processors, and trying to run the wrong one on your system will not work. Usually the processor type is added as part of the package name.

Once you download the DEB package, use dpkg with the -i option to install it:
$ sudo dpkg -i zsh_5.3.1-4+b2_amd64.deb
Selecting previously unselected package zsh.
(Reading database ... 204322 files and directories currently installed.)
Preparing to unpack zsh_5.3.1-4+b2_amd64.deb ...
Unpacking zsh (5.3.1-4+b2) ...
dpkg: dependency problems prevent configuration of zsh:
zsh depends on zsh-common (= 5.3.1-4); however:
Package zsh-common is not installed.
dpkg: error processing package zsh (--install):
dependency problems - leaving unconfigured
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Errors were encountered while processing:
zsh
You can see in this example that the package management software checks to ensure that any packages that are required for the application are installed and produces an error message if any of them are missing. This gives you a clue as to what other packages you need to install.
 

If you'd like to see all of the packages installed on your system, use the -l option:
$ dpkg -l
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-============-============-===========================
ii accountsservic 0.6.45-1ubun amd64 query and manipulate accounts
ii acl 2.2.52-3buil amd64 Access control list utilities
ii acpi-support 0.142 amd64 scripts for handling ACPI
ii acpid 1:2.0.28-1ub amd64 Advanced Config and Power
ii adduser 3.116ubuntu1 all add and remove users
ii adium-theme-ub 0.3.4-0ubunt all Adium message style for Ubuntu
ii adwaita-icon-t 3.28.0-1ubun all default icon theme of GNOME
ii aisleriot 1:3.22.5-1 amd64 GNOME solitaire card game
You can also provide a search term on the command line to limit the packages returned in the output:
$ dpkg -l openssh*
+++-==============-============-============-=============================
ii openssh-client 1:7.6p1-4ubu amd64 secure shell (SSH) client
un openssh-server <none> <none> (no description available)

If you need to remove a package, you have two options. The -r action removes the package but keeps any configuration and data files associated with the package installed. This is useful if you're just trying to reinstall an existing package and don't want to have to reconfigure things. If you really do want to remove the entire package, use the -P action, which purges the entire package, including configuration files and data files from the system.
-p and -P options. They're easy to mix up. The -p option lists the packages, whereas the -P option purges the packages. Quite a difference!
The dpkg tool gives you direct access to the package management system, making it easier to install applications on your Debian-based system.

Red Hat Package Tools
The Red Hat Linux distribution, along with other Red Hat–based distributions such as Fedora, Rocky, and CentOS, use the RPM package file format. The main tool for working with RPM files is the rpm program.
Similar to the dpkg tool, the rpm program is also a command-line program to install, modify, and remove RPM software packages. The basic format for the rpm program is as follows:
rpm action [options] package-file

To use the rpm command, you must have the RPM package file downloaded onto your system. While you can use the -i action to install packages, it's more common to use the -U action, which installs the new package or upgrades the package if it's already installed. Adding the -vh option is a popular combination that shows the progress of the update and what it's doing:
$ sudo rpm -Uvh zsh-5.0.2-31.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:zsh-5.0.2-31.el7 ################################# [100%]

TABLE: The rpm command actions

 

 

Action Description
-b Builds a binary package from source files
-e Uninstalls the specified package
-F Upgrades a package only if an earlier version already exists
-i Installs the specified package
-q Queries if the specified package is installed
-U Installs or upgrades the specified package
-V Verifies if the package files are present



You use the -q action to query the package management database for installed packages:
$ rpm -q zsh
zsh-5.0.2-31.el7.x86_64
If you need to remove an installed package, just use the -e action:
$ sudo rpm -e zsh
$ sudo rpm -q zsh
package zsh is not installed

The -e action doesn't show if it was successful, but it will display an error message if something goes wrong with the removal.

Understanding Repositories
The dpkg and rpm commands are useful tools, but they both have their limitations. If you're looking for new software packages to install, it's up to you to find them. Also, if a package depends on other packages to be installed, it's up to you to install those packages first and in the correct order. That can become somewhat of a pain to keep up with.
To solve that problem, each Linux distribution has its own central clearinghouse of packages, called a . The repository contains software packages that have been tested and known to install and work correctly in the distribution environment. By placing all known packages into a single repository, the Linux distribution can create a one-stop shopping environment for installing all applications for the system.
Most Linux distributions create and maintain their own repositories of packages. There are also additional tools for working with package repositories. These tools can interface directly with the package repository to find new software and even automatically find and install any dependent packages the application requires to operate.
Besides the officially supported distribution package repositories, many third-party package repositories have sprung up on the Internet. Often specialized or custom software packages aren't distributed as part of the normal Linux distribution repository but are available in third-party repositories. The repository tools allow you to retrieve those packages as well.

The following sections walk through how to use the Debian and Red Hat repository tools.

Debian Repository Tools
The core tool used for working with Debian repositories is the apt suite of tools. This includes the apt-cache program, which provides information about the package database, and the apt-get program, which does the work of installing, updating, and removing packages. To make things easier, the apt program is a front-end script that can call either of the core programs as needed.
The apt suite of tools relies on the /etc/apt/sources.list file to identify the locations of where to look for repositories. By default, each Linux distribution enters its own repository location in that file, but you can add additional repository locations as well if you install third-party applications not supported by the distribution.

There are a few useful command options in the apt-cache program for displaying information about packages:
depends: Displays the dependencies required for the package
pkgnames: Displays all the packages installed on the system
showpkg: Displays information about the specified package
stats: Displays package statistics for the system
unmet: Displays any unmet dependencies for installed packages
The workhorse of the apt suite of tools is the apt program. It's what you use to install and remove packages from a Debian package repository.


TABLE: The apt program action commands

 

 

Action Description
autoremove Removes any unneeded packages automatically installed as a dependency of another installed package
full-upgrade Works the same as upgrade but will remove any installed packages required to upgrade the entire system
install Installs a new software package from the repository
list Displays the currently installed packages
purge Removes the specified application, along with any configuration or data files
reinstall Attempts to reinstall an existing package from the repository
remove Removes the specified application, but keeps any configuration or data files
satisfy Attempts to resolve software dependencies in the installed packages
search Searches for a specific package in the repository
show Displays information about the specified package
update Downloads package information from all configured repositories
upgrade Installs available upgrades from all installed packages



Installing a new package from the repository is as simple as specifying the package name with the install action:
$ sudo apt install zsh
Building dependency tree
Suggested packages:
zsh-doc
The following NEW packages will be installed:
zsh
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 707 kB of archives.
After this operation, 2,390 kB of additional disk space will be used.
Fetched 707 kB in 1s (731 kB/s)
(Reading database ... 195185 files and directories currently installed.)
Preparing to unpack .../zsh_5.8-3ubuntu1_amd64.deb ...
Unpacking zsh (5.8-3ubuntu1) ...
Setting up zsh (5.8-3ubuntu1) ...
Processing triggers for man-db (2.9.1-1) ...

If any dependencies are required, the apt program retrieves those as well and installs them automatically.
Tip: upgrade action provides a great way to keep your entire Debian-based system up-to-date with both package and kernel updates released to the distribution repository. Running that command will ensure that your packages and the Linux kernel have all the security and bug fixes installed. However, that also means that you fully trust the distribution developers to put only tested packages in the repository. Occasionally a package may make its way into the repository before being fully tested and cause issues.

Red Hat Repository Tools
In the past, the core tool used for working with Red Hat repositories has been the yum tool (short for YellowDog Update Manager, originally developed for the YellowDog Linux distribution). This tool has recently been replaced by the dnf tool, which is an updated version of yum with additional features added. The dnf tool allows you to query, install, and remove software packages on your system directly from a Red Hat repository.
Both the yum and dnf commands use the /etc/yum.repos.d folder to hold files that list the different repositories it checks for packages.

For a default Rocky Linux system, that folder contains several repository files:
$ cd /etc/yum.repos.d
total 88
drwxr-xr-x. 2 root root 4096 Nov 30 09:15 .
drwxr-xr-x. 150 root root 8192 Dec 27 09:34 ..
-rw-r--r--. 1 root root 1485 Sep 4 13:28 epel-modular.repo
-rw-r--r--. 1 root root 1564 Sep 4 13:28 epel-playground.repo
-rw-r--r--. 1 root root 1422 Sep 4 13:28 epel.repo
-rw-r--r--. 1 root root 1584 Sep 4 13:28 epel-testing-modular.repo
-rw-r--r--. 1 root root 1521 Sep 4 13:28 epel-testing.repo
-rw-r--r--. 1 root root 700 Oct 8 19:29 Rocky-AppStream.repo
-rw-r--r--. 1 root root 685 Oct 8 19:29 Rocky-BaseOS.repo
-rw-r--r--. 1 root root 1753 Oct 8 19:29 Rocky-Debuginfo.repo
-rw-r--r--. 1 root root 350 Oct 8 19:29 Rocky-Devel.repo
-rw-r--r--. 1 root root 685 Oct 8 19:29 Rocky-Extras.repo
-rw-r--r--. 1 root root 721 Oct 8 19:29 Rocky-HighAvailability.repo
-rw-r--r--. 1 root root 680 Oct 8 19:29 Rocky-Media.repo
-rw-r--r--. 1 root root 670 Oct 8 19:29 Rocky-NFV.repo
-rw-r--r--. 1 root root 680 Oct 8 19:29 Rocky-Plus.repo
-rw-r--r--. 1 root root 705 Oct 8 19:29 Rocky-PowerTools.repo
-rw-r--r--. 1 root root 736 Oct 8 19:29 Rocky-ResilientStorage.repo
-rw-r--r--. 1 root root 671 Oct 8 19:29 Rocky-RT.repo
-rw-r--r--. 1 root root 2335 Oct 8 19:29 Rocky-Sources.repo

Each file in the yum.repos.d folder contains information on a repository, such as the URL address of the repository and the location of additional package files within the repository. The yum program checks each of these defined repositories for the package requested on the command line.
The dnf program is very versatile.


TABLE: The dnf action commands

 

 

Action Description
alias Defines an alias that points to a list of other dnf commands
autoremove Removes any packages installed as a dependency that is no longer needed
check Examines the local package database and reports any problems
check-update Checks the repository for updates to a specified package
clean Performs cleanup of temporary files kept for repositories
deplist Deprecated alias for the repoquery command
distro-sync Downgrades or installs packages to place the system in sync with the current repositories
downgrade Downgrades the specified package to the version available in the repository
group Manages a set of packages as a single entity
help Displays help for the dnf command
history Displays previous dnf commands
info Displays information about an installed and available package
install Installs the current version of a package from the repository
list Displays all installed and available packages
makecache Downloads metadata for the repositories
mark Marks a specified package as being installed
module Manages module packages
provides Displays the package that installed the specified file
reinstall Attempts to reinstall the specified package
remove Removes the specified package from the system, including any packages that depend on the specified package
repoinfo Displays information about the configured repositories
repolist Displays a list of the currently configured repositories
repoquery Searches the configured repositories for the specified package
repository-packages Runs commands on all packages in the repository
search Searches package metadata for specified keywords
shell Displays an interactive shell for entering multiple dnf commands
swap Removes and reinstalls the specified package
updateinfo Displays update advisory messages
upgrade Installs the latest version of the specified packages, or all packages if none specified
upgrade-minimal Installs only the latest package versions that provide a bugfix or security fix



Installing new applications is a breeze with dnf:
$ sudo dnf install zsh
Last metadata expiration check: 0:00:19 ago on Mon 27 Dec 2021 20:04:03 AM EST.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
Installing:
zsh x86_64 5.5.1-6.el8_1.2 baseos 2.9 M
Transaction Summary
Install 1 Package
Total download size: 2.9 M
Installed size: 6.9 M
Is this ok [y/N]: y
zsh-5.5.1-6.el8_1.2.x86_64.rpm 1.1 MB/s | 2.9 MB 00:02
------------------------------------------------------------------------------
Total 376 kB/s | 2.9 MB 00:07
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : zsh-5.5.1-6.el8_1.2.x86_64 1/1
Running scriptlet: zsh-5.5.1-6.el8_1.2.x86_64 1/1
Verifying : zsh-5.5.1-6.el8_1.2.x86_64 1/1
Installed:
zsh-5.5.1-6.el8_1.2.x86_64

One nice feature of dnf is the ability to group packages for distribution. Instead of having to download all of the packages needed for a specific environment (such as for a web server that uses the Apache, MySQL, and PHP servers), you can download the package group that bundles the packages together. This makes for an even easier way to get packages installed on your system.

Tip: yum or dnf tools. Instead, openSUSE has created its own package manager called ZYpp. The main tool in the ZYpp package is the zypper program.

Graphical Package Tools
Both the Debian-based and Red Hat–based package management systems have graphical tools for making it easier to install software in desktop environments. One tool that is available in both the Ubuntu and Rocky distributions is gnome-software.
The gnome-software program is a graphical front end to the PackageKit tool, which itself is a front end that standardizes the interface to multiple package management tools, including apt and yum. By including both PackageKit and gnome-software, Linux distributions can provide a standard graphical interface for users to manage their software packages.

Figure below shows the gnome-software package as it appears in the Ubuntu 20.04 Linux distribution.
Snapshot shows the Ubuntu Software package graphical tool
Figure: The Ubuntu Software package graphical tool

You can search for packages, view the installed packages, and even view the updated packages available in the repository. If you're using the Rocky Linux distribution, the gnome-software interface looks the same.

Finally, some standardization is happening across Linux distributions, at least where it comes to graphical software package management tools.
Snapshot shows the Rocky Linux software package graphical tool
Figure: The Rocky Linux software package graphical tool

Using Application Containers
A relatively new feature in the Linux world is the use of containers. Containers allow you to bundle all of the files required for an application, including any dependencies, into one distribution package—the container. This ensures that you can install everything needed to run an application at once, and that all the files required to run an application are available, no matter what platform you install the container on.
The downside to this method, though, is that any dependencies shared among multiple applications are duplicated for each application. However, this method ensures that each application has exactly the correct dependencies (and versions) required to run properly, and it is quickly gaining in popularity, especially in environments where applications may need to switch servers frequently.
As expected, there are multiple application container formats available in the Linux world. This section discusses the two that are covered in the Linux+ exam.

Using Snap Containers
Canonical, the creators of the Ubuntu Linux distribution, have developed an application container format called snap
. The snapd application manages the snap packages installed on the system and runs in the background. You use the snap command-line tool to query the snap database to display installed snap packages, as well as to install, upgrade, and remove snap packages.

To check whether snap is running on your system, use the snap version command:
$ snap version
snap 2.47.1+20.04
snapd 2.47.1+20.04
series 16
ubuntu 20.04
kernel 5.4.0-53-generic

If snap is running, you can see a list of the currently installed snap applications by using the snap list command:
$ snap list
Name Version Rev Tracking Publisher Notes
core18 20200929 1932 latest/stable canonical* base
lxd 4.0.4 18150 4.0/stable/... canonical* -
snapd 2.47.1 9721 latest/stable canonical* snapd

To search the snap repository for new applications, use the snap find command:
$ snap find stress-ng
Name Version Publisher Notes Summary
stress-ng V0.11.24 cking-kernel-tools - A tool to load, stress test and
benchmark a computer system

To view more information about a snap application, use the snap info command:
$ snap info stress-ng
name: stress-ng
summary: A tool to load, stress test and benchmark a computer system
publisher: Colin King (cking-kernel-tools)
store-url: https://snapcraft.io/stress-ng
contact: [email protected]
license: GPL-2.0
description: |
stress-ng can stress various subsystems of a computer. It can stress load
CPU, cache, disk, memory, socket and pipe I/O, scheduling and much more.
stress-ng is a re-write of the original stress tool by Amos Waterland but
has many additional features such as specifying the number of bogo
operations to run, execution metrics, a stress verification on memory and
compute operations and considerably more stress mechanisms.
snap-id: YMJsyW4vySPdys8BCA7jx8UiOVSVhUT6
channels:
latest/stable: V0.11.24 2020-11-13 (5273) 3MB -
latest/candidate: V0.11.24 2020-11-13 (5273) 3MB -
latest/beta: V0.11.24 2020-11-13 (5273) 3MB -
latest/edge: V0.11.24-44-20201121-7613-g2627a 2020-11-21 (5298) 3MB –

To install a new snap, use the snap install command.
$ sudo snap install stress-ng
[sudo] password for rich:
stress-ng V0.11.24 from Colin King (cking-kernel-tools) installed

You can check that the software container was installed by using the list command:
Name Version Rev Tracking Publisher Notes
core18 20200929 1932 latest/stable canonical* base
lxd 4.0.4 18150 4.0/stable/... canonical* -
snapd 2.47.1 9721 latest/stable canonical* snapd
stress-ng V0.11.24 5273 latest/stable cking-kernel-tools -
Finally, you can remove an installed application container by using the remove command:
$ sudo snap remove stress-ng
stress-ng removed

As the snap is removed, you'll see some messages about the progress of the removal. Instead of removing a snap, if you prefer you can just disable it without removing it. Just use the snap disable command. To reenable the snap, use the snap enable command.

Using Flatpak Containers
The flatpak application container format was created as an independent open source project with no direct ties to any specific Linux distribution
. That said, battle lines have already been drawn, with Red Hat–based Linux distributions oriented toward using flatpak instead of Canonical's snap container format.
dnf or rpm method.

To display the current flatpak containers installed on the system, use the list command:
$ flatpak list

Not too exciting. When you first install flatpak there won't be any containers installed, but now you know that flatpak is installed.

By default Red Hat–based Linux distributions don't configure any repositories for flatpak (repositories in flatpak are called remotes).

The most popular flatpak remote is Flathub. Currently, to set flatpak to point to the Flathub remote you use the following:
$ sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
To find an application in the flatpak repository, you use the flatpak search command:
$ sudo flatpak search mosh
Name Description Application ID Version Branch Remotes
Mosh The Mobile Shell org.mosh.mosh 1.3.2 stable flathub

When working with a container, you must use its Application ID value and not its name. To install the application, use the flatpak install command:
$ sudo flatpak install org.mosh.mosh
Looking for matches...
Found similar ref(s) for 'org.mosh.mosh' in remote 'flathub' (system).
Use this remote? [Y/n]: Y
Required runtime for org.mosh.mosh/x86_64/stable (runtime/org.freedesktop.Platform/x86_64/21.08) found in remote flathub
Do you want to install it? [Y/n]: Y
org.mosh.mosh permissions:
network ssh-auth
ID Branch Op Remote Download

1. org.freedesktop.Platform.GL.default 21.08 i flathub 130.9 MB / 131.2 MB

2. org.freedesktop.Platform.Locale 21.08 i flathub 17.7 kB / 325.0 MB

3. org.freedesktop.Platform.openh264 2.0 i flathub 1.5 MB / 1.5 MB

4. org.freedesktop.Platform 21.08 i flathub 153.7 MB / 198.9 MB

5. org.mosh.mosh stable i flathub 10.5 MB / 12.7 MB
Installation complete.
To check if the installation went well, use the flatpak list command again:
Name Application ID Version Branch Installation
Freedesktop Plat... org.freedesktop.Platform 21.08.7 21.08 system
Mesa ...freedesktop.Platform.GL.default 21.3.1 21.08 system
openh264 ...g.freedesktop.Platform.openh264 2.1.0 2.0 system
Mosh org.mosh.mosh 1.3.2 stable system
And finally, to remove an application container, use the flatpak uninstall command:
$ sudo flatpak uninstall org.mosh.mosh
ID Branch Op

1. [-] org.mosh.mosh stable r
Uninstall complete.

Working with flatpak containers is a bit different from using package management systems, but once you get comfortable with the format of things, it's not all that different from the standard package management system.
- AppImage is yet another format for distributing software in the Linux world. AppImage is a bit different in that standard users don't need root privileges to install an AppImage package on the system. Instead of installing the software in the standard Linux system directories, AppImage distributes applications as a compressed disk image that standard users can mount in their Home directories and run. Of course, this means each individual user on the system who wants to run the application has to download a separate AppImage file to run the application.

EXERCISE: Working with Packages
This exercise demonstrates how to work with a package management system to install software.

  1. Display the packages currently installed on your system. For Debian-based systems such as Ubuntu, use the command sudo apt-cache pkgnames. For Red Hat–based systems such as Rocky, use the command sudo dnf list.
  2. If it's not already installed on your system, install the zsh shell package. For Debian-based systems, use the command sudo apt install zsh. For Red Hat–based systems, use the command sudo dnf install zsh. If the zsh package is already installed, try installing the tcsh package, which is an open source version of the C shell found in many Unix systems.
  3. Display the installed packages on your system again to see if the newly installed package appears.
  4. Now remove the package from your system. For Debian-based systems, use the command sudo apt remove zsh. For Red Hat–based systems, use the command sudo dnf remove zsh.
  5. Display the installed packages yet again to see if the package was properly removed.

The ability to easily install and remove applications is a must for every Linux system. In the open source world, developers release their applications as source code bundles using the tar and gzip utilities to create a tarball file. After you download a tarball file, you must decompress and extract the files it contains to be able to compile the application. The gcc program is the most common program for compiling many open source applications. You use the configure and make utilities to create and run installation scripts to make it easier to install applications from source code.
Most Linux distributions help simplify application installation by precompiling the source code and bundling the necessary application files into a package. Package management software makes it easier to track what applications are installed on your Linux system and where their files are located. Debian-based Linux distributions use the DEB package management format, with the dpkg tool, while Red Hat–based Linux distributions use the RPM package management format, with the rpm tool.
While package management systems make it easier to install and remove packages, it's still somewhat of a hassle finding packages. Most Linux distributions now maintain their own repository of packages and provide additional tools, making it easier to retrieve and install packages from the repository. For Debian-based systems, the apt suite of tools, including apt-cache and apt-get, and apt are used to retrieve packages from the repository and maintain the package management database. For Red Hat–based systems, either yum or dnf is the package tool to use.
Application containers are now becoming somewhat popular in the Linux world. An application container bundles all software required to run an application, including dependency applications and all libraries, into a single installation package. The two most popular application container formats are snap and flatpak.

Important Exam Topics:

1. Describe how developers bundle their open source applications for distribution.
- Linux developers bundle source code files, headers, libraries, and documentation files into a single file for distribution. They use the tar utility to archive multiple files and folders into a single archive file and then often compress the archive file using the gzip utility. You can use the wget or cURL program to download the source code distribution files and then use the gzip and tar utilities to decompress and extract the source code files.

2. Explain how to generate an executable program from a source code tarball.
- After you decompress and extract the source code files from a distribution tarball file, you must compile the source code to create an executable file for the application. First, you must use the configure utility. This examines your Linux system to ensure that it has the correct dependencies required for the application and configures the installation script to find the dependencies. Next, you run the make utility. The make utility runs a script that uses the gcc compiler to compile the necessary library and source code files to generate the executable file for your system. Once that script completes, use the make script with the install option to install the executable file on your Linux system.

3. Describe how Linux packages applications for distribution.
- Linux uses a package management system to track what applications are installed on your system. The distribution bundles precompiled application files into a package, which you can easily download and install. The package management database keeps track of which packages are installed and the location of all the files contained within the package. You can also query the package management database to determine what packages are installed and remove packages from the system using the package management tools. Debian-based Linux systems use the dpkg tool to interact with the package management database, whereas Red Hat–based Linux systems use the rpm tool.

4. Describe how Linux distributions use repositories.
- While using packages makes installing, tracking, and removing software applications easier, you still must be able to find the latest packages for your applications. Most Linux distributions help with that by creating a centralized repository of current application packages, along with tools to work with the repository. For Debian-based systems, the apt suite of tools allows you to query the repository for package information and download any new or updated packages. Red Hat–based systems use the yum or dnf tool to interact with their repositories. All three tools allow you to query the remote repository for packages, query the local package management database, and install or remove packages as you need.

5. Explain how application containers differ from package management systems.
- Application containers such as snap and flatpak bundle all of the files required to run an application, including any dependency applications, into a single package. While this can create duplicate copies of dependent applications, it ensures that each application has exactly the correct version of libraries and dependent applications installed to work, making it a breeze to move applications from one system to another.