Linux Software Management

Share This Post:

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
Linux-software-management-850

Another key administrative skill , as evidenced by the fact it is on the Linux + certification is having a firm grasp of Linux software management.

A Linux system itself is kind of like a base model automobile, pretty boring to most people;  understanding Linux software management allows you to add and remove applications to the system.  Developing your Linux software management skills means knowing:

  • The role of software on your Linux system 
  • How to get, compile and manage Linux software.
  • How open source software is created.
  • How Linux distribution often bundle pre-built software packages to simplify the  installation and removal of applications.

Understanding Linux Source Code

The term open-source refers to the ability to inspect/modify a program’s underlying code which is in contrast to commercial applications, which hide their source code. Most applications in the Linux environment open-source projects,  Secur’s objective for this article is walking readers through the downloading, extracting, compiling, and running of open-source application code.

Downloading Source Code

Many developers release their open-source applications by building out  a website to host code and documentation, for users to download it, how ever this doesn’t always work, especially in Linux server environments, and Linux software management requires using a number of command-line tools to download source code files directly from the command line:

  • wget: command-line tool from the GNU Project that allows you to retrieve files from remote servers using FTP, FTPS, HTTP, or HTTPS with the following syntax:

wget http:///

    • Specify the:
      • Protocol
      • Server name
      • File to download using a standard URL format, where:
        • Remotehost is the full hostname for the location hosting the files,
        • Filename is the name of the file to retrieve, including the folder path required:
    •  wget supports lots of command-line options to customize the connection and download.
  •  cURL: 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.
    • uses the standard URL format to specify the protocol, server name, and file to download.
    • Warn if the remote website is using a self-signed or untrusted certificate authority (CA).
  • GitHub: provides centralized location and use the git version control system.
    • Use either “wget” and “cURL” to download project code from GitHub.

Bundling Application Source Code Packages

Distributing application source code can be cumbersome as projects often comprise different files types:

  • Source code files
  • Header files
  • Library files
  • Documentation files

The tar program, developed for archiving files and folders to tape drives for backups, is often used for bundling project files to distribute on the Internet as 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.  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

 

The two screenshot below show the process used to create a new tar archive. 

  • The first screenshot shows the correct file creation process, specifying the output file name and then listing the files/folders to bundle. 
    • For the input files and folders, you can use wildcard characters to specify the names, or redirect a listing of files to the “tar” command
  • The second screenshot shows that you can run “tar” without specifying the output name but you find that what you done is written over the first file in your archive list and turned it into an archive file
Proper filenames tar
Proper use of the "tar" command.
tar Linux
Using "tar" to build an archive without specifying an archive file name.

As seen in the screenshot below, use the “-tvf” option group to inspect the contents of a tar archive file. As the file ownerships and the file permissions are retained within the tar archive file, when you extract the files onto another system, they get assigned to the userid that matches the user number assigned to the original files.

Viewing tar files
Viewing tar files with the "-tvf" options.

The screenshot below shows the expansion of a tar file.

Expanding a tar file
Using the "-xvf" option to expand a tar file.

After creating an archive, which preserves the file ownership and structure, you will probably need to compress the archive.  The table below provides you with a quick summary of file compression techniques.

MethodFile ExtensionDescription
bzip2.bz2Reduced file side compared to the gzip method.
compress.ZUnix compression program.
gzip.gzModerately sized compressed file.
xz.xzSlow file creation, small file size.

The screenshots below show:

  • The compression of an archive with the “gzip” utility.
  • The decompression and unpacking of an archive in one step with the “tar” command’s “-zxvf” option.  When the “gunzip” program runs, it removes the compressed file , but when you use the “-z” option with the “tar” program, it retains the compressed and extracted original files.
gzip linux
Compressing a tar archive with a "gzip" utility.
tarball decompression
Decompressing and unarchiving a tarball in one step.

Linux Package Source Code Compilation

After downloading source code package files to a Linux system, they must be compiled to create an executable file that run the actual application. As Linux supports a range of programming languages, you need to know the language the files were written in to be able to select and install the correct compiler, a tool that converts source code into a Linux executable file. The GNU Compiler Collection (gcc) is the most common tool used for compiling programs in Linux and supports array of different programming languages, such as C, Ada, C++, Fortran, Go, Java, Objective-C, Objective-C++, and OpenMP. Most Linux distributions don’t include the gcc program by default, so most likely you’ll need to install it on your Linux system:

  • For Ubuntu, you find it in the build-essentials package.
  • For CentOS you’ll find it in the Development Toolspackagegroup.
 
In the screenshot below, we wrote and complied a very simple one-file program, “first_program.c” and compiled it with gcc, using the output name “first_program“.  We then execute the file with the “./” command followed by the file name.  
In addition to source code files, most larger applications require header/library files in order to build the final application file so the “gcc” command process gets complicated depending on just how many source code, header, and library files are required for an application.  Since separate library files need to be compiled in the proper order before compiling the main program,  the application generation road map gets complex.
Gcc compilation Linux
Using ggc to compile a very simple program on a Linux system.

The "make" Utility

The “make” utility allows the creation of scripts that compiling and instal application source code packages in three steps:
1. Run the “configure” utility:  Analyzes the Linux system environment, customizes the “make” script to build the application for the environment.
2. Run the “make” utility by itself:  Builds the necessary library files and executable files for the application.
3. Run “make install” as root user account, installing the application files in the appropriate locations on your system.

C language programs are often complicated as the split application
functions into separate library files, containing one or more specialized functions.

  • The benefit of splitting functions into separate library files is that applications using the same functions can share the same library files, which surprisingly, are called shared libraries, 
    • make it easier to distribute applications
    • more complicated to track the library files
  • The “ldd” utility displays a list of the library files required for a specified application file, as well as their locations, and can help identify track down missing application library files.  In the screenshot below, we ran “ldd” against the “first_program” file, a simple program requiring two external library:
    • linux- vdso.so.1
    • libc.so.6 files, which provide the ability for the printf() function to display the output.
ldd command

Packaging Linux Applications

As described previously, “tar“, “gcc”  and “make” facilitate application source code distribution, compilation, and installation, but it still involves a level of tinkering that is too complex for Linux user to install an application.

The solution to this problem comes in the form of a bundling system called a “package“, an object consisting of all the files required to manage (install/remove) a single application. to avoid dealing with group of obtusely named files.  Software packages are tracked via a  “package management” database that tracks the installed packages on the system, allowing users to:

  • Determine what applications are installed on your system is as easy as querying the pack- age management database.
  • Keep track of :
    • Which packages are installed
    • The exact files and file locations required for each application.

Different Linux distributions use different methods for their package management systems but they all rely on a package management database that track similar information including:

  • 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
    • Warns if a dependent library file not present when you install a package.
  • Application version:  Tracks version numbers of applications so that you know when an updated version of the application is available.

 

If a package depends on other packages to be installed, you need to install those packages first and in the correct order, which can be a pain in the neck.   The solution to this problem comes in the form of a “software repository“; each Linux distribution has a central clearinghouse of packages containing tested software packages .There are also additional tools for working with package repositories. These tools

  • Interface directly with the package repository to find new software and even automatically 
  • Find/install any dependent packages the application requires to operate.
  • Specialized or custom software packages not distributed as part of the normal Linux distribution package but are available in third-party repositories. 

Debian Package Management Tools

Will it may be a blinding flash of the obvious to some, the Debian package management system is mostly used on Debian-based Linux systems, and is defined by the following characteristics.

  • Debian bundles application files into a  “.deb” package file for distribution.
  • The “dpkg” program is a command-line utility tool for handling .deb files.
    • 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.  
        • Each action has a set of options that you can use to modify the basic behavior of the action.
        • You can see a list of these actions in the table below.
      • To use the “dpkg” program, you must have the “.deb” software package available.
      • You can find .deb versions of application packages ready for distribution on the application website, or a central repository.  Debian maintains acentral clearinghouse for Debian packages at https://www.debian.org/distrib/packages.
      • When downloading a “.deb” package for a precompiled application, ensure you get the correct package for your  processor chip as source code files are compiled for specific processors, .
ActionDescription
-CSearches for broken installed packages
and suggests how to fix them.
–configureReconfigures an installed package
–get-selectionsDisplays currently installed packages
-iInstalls the package
-I (Capital “i”)Displays information about an uninstalled package file
-l (Lowercase “L”)Lists all installed packages matching a specified pattern.
-pDisplays information about an installed package.
-PRemoves an installed package, including configuration files.
-rRemoves an installed package but leaves the configuration files.
-SLocates the package that owns the specified files.

The two images below show:

  • Using “wget” to download an application.
  • Using “dpkg” with the “-i” option to attempt to install the application.
  • You can see that this installation attempt failed as the package management software checks to ensure that any packages that are required for the application are installed and produces an error message because they were missing. 
wget download
Using wget to download the connman-vpn application.
sudo dpkg linux
Using "dpkg" to install an application that was download.

In the following 2 screenshots, you will see the use of the “-l“:

  • If you’d like to see all of the packages installed on your system, use the “-l” option:
  • You can also provide a search term (in this case “wget“) on the command line to limit the packages returned in the output

Package removal can be done two way:

-r” removes a package but keeps configuration and data files associated with the package installed.

  • Use this if you’re just trying to reinstall an existing package.

The” -P” action purges the entire package, including configuration files and data files from the system.  Be careful with the “-p” and “-P” options. The “-p” option lists the packages, while the “-P” option purges the packages. 

dpkg -l
Using "dpkg -l" to list all the packages.
dpkg
Using dpkg to search for one package.

Red Hat /CentOs Package Management Tools

The Red Hat Linux group of Linux distributions, which include Fedora and CentOS, make use the “.rpm” package file format and the tool for working with .rpm files is the rpm program.  Also a command line tool, rpm installs, modifies, and removes .rpm software packages with the following basic syntax:

rpm action [options] package-file

To use the rpm command, you must have the .rpm package file downloaded onto your system and use the following actions and options to manage packages:

  • The “-i” action to install packages, it’s more common to use the
  • The “-U” action, which installs the new package or upgrades the package if it’s already installed.
  • The “-vh” option  shows the progress of the update and what it’s doing.
  • The “-q” action determines if a package is installed.
  • Use the “-e” action to remove an installed package. It doesn’t show if it was successful, but displays an error message if something goes wrong with the removal.

Working With Linux Repositories

Using Debian Repository Tools

When you think of Debian repositories the “apt” suite of tools should come to mind. 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.and include:

  • apt-cache: provides information about the package database
  • apt-get: used for installing, updating, and removing packages.  Retrieves any required dependencies and installs them automatically.
  • There are a number of command options are useful for displaying information about packages:
    • autoclean: Removes information about packages that are no longer in the repository.
    • check: Checks the package management database for inconsistencies .
    • clean: Cleans up the database and any temporary download files.
    • depends: Displays the dependencies required for the package
    • dist-upgrade: Upgrades all packages, but monitors for package dependencies .
    • dselect-upgrade: Completes any package changes left undone.
    • install: Installs a package and updates the package management database.
    • pkgnames: Displays all the packages installed on the system.
    • remove: Removes a package from the package management database.
    • showpkg: Displays information about the specified package
    • source: Retrieves the source code package for the specified package.
    • stats: Displays package statistics for the system.
    • unmet: Displays any unmet dependencies for installed packages.
    • update: Retrieves updated information about packages in the repository.
    • upgrade: Upgrades all installed packages to newest versions and is a great way to keep your system up-to-date with the packages released to the distribution repository.  Additionally, it ensures that packages have all the security and bug fixes installed but means that you trust the developers to put only tested packages in the repository. 

Red Hat / CentOS Repository Tools

The “yum” tool, which is an acronym for “YellowDog Update Manager” that was part of the YellowDog Linux distribution, is the main tool used for working with Red Hat repositories; it allows you to query, install, and remove software packages on your system directly from a Red Hat repository.

The “yum” command checks the files that list the different repositories in the “/etc/yum.repos.d” for the package requested on the command line.  Each file in “yum.repos.d” folder contains information on a repository:

  • The URL address of the repository
  • The location of additional package files within the repository.
 

Rather than needing to download all of the packages needed for a specific environment, “yum” groups packages for distribution so you can simply download the package group that bundles the packages together, making it easier to install get packages on your system.  The “yum” action commands include:

  • check-updateChecks the repository for updates to installed packages.
  • cleanRemoves temporary files downloaded during installs.
  • deplist: Displays dependencies for the specified package.
  • infoDisplays information about the specified package.
  • install: Installs the specified package.
  • listDisplays information about installed packages.
  • localinstallInstalls a package from a specified .rpm file.
  • localupdateUpdates the system from specified .rpm files.
  • providesDisplays information about packages that provide a feature
  • removeRemoves a package from the system.
  • resolvedepDisplays packages matching the specified dependency
  • searchSearches repository package names and descriptions for specified keyword.
  • shellEnters yum command-line mode.
  • updateUpdates the specified package(s) to the latest version in the repository.
  • upgradeUpdates specified package(s), but removes obsolete packages.

Graphical Package Management Tool

Most package management systems offer users a number of graphical tools for making it easier to install software in desktop environments.  A good example of these tools is the wonderfully named “gnome-software“, a graphical front end to the PackageKit tool which interfaces to multiple package management tools including “apt” and “yum“.

The screenshots below shows the gnome-software package as it appears in the Ubuntu 20.04 Linux distribution.  The UI allows you to:

  • Search for packages.
  • View the installed packages.
  • View the updated packages available in the repository.
Gnome-software
Screenshot of "gnome-software" user interface.
Gnome-software linux
Screenshot of "gnome-software" user interface.

Share This Post:

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents

You May Like

Related Posts

Linux Basics
Linux Administrator

How to Manage Storage on Linux

Knowing how to manage storage on Linux is an essential skill for both hackers and administrators.   Administrators need to optimize the processes for storing and

Read More »
tor logo
Privacy
Linux Administrator

Understanding How To Use Tor

Understanding how to use Tor is essential if you are looking to reduce your online exposure and keep your web surfing private. Tor Overview Network

Read More »
Networking
Linux Administrator

How Do Computers Communicate ?

Given the pervasiveness of the Internet in our daily lives, understanding how computers communicate with one another is essential to improving your online security.  In

Read More »