Reader small image

You're reading from  Mastering Ubuntu Server - Fourth Edition

Product typeBook
Published inSep 2022
PublisherPackt
ISBN-139781803234243
Edition4th Edition
Concepts
Right arrow
Author (1)
Jay LaCroix
Jay LaCroix
author image
Jay LaCroix

Jeremy "Jay" LaCroix is a technologist and open-source enthusiast, specializing in Linux. He has a net field experience of 20 years across different firms as a Solutions Architect and holds a master's degree in Information Systems Technology Management from Capella University. In addition, Jay also has an active Linux-focused YouTube channel with over 250K followers and over 20M views, available at LearnLinuxTV, where he posts instructional tutorial videos and other Linux-related content. He has also written Linux Mint Essentials and Mastering Linux Network Administration, published by Packt Publishing.
Read more about Jay LaCroix

Right arrow

Managing Software Packages

Now that you have a server installation set up, and you know how to manage users on it, it’s time to cover the management of software. The Ubuntu platform has a huge range of software available, featuring packages for everything from server administration to games. In fact, as of the time I’m writing this chapter, there are over 60,000 packages in Ubuntu’s repositories. That’s a lot of software packages, and in this chapter, we’ll take a look at how to manage them. We’ll cover how to install, remove, and update packages, as well as the use of related tools.

As we go through these concepts, we will cover:

  • Understanding Linux package management
  • Understanding the differences between Debian and Snap packages
  • Installing and removing software
  • Searching for packages
  • Managing package repositories
  • Backing up and restoring Debian packages
  • Cleaning up orphaned APT packages
  • ...

Understanding Linux package management

Nowadays, app stores are all the rage on most platforms; typically, you’ll have one central location from which to retrieve applications, allowing you to install them on your device. Even phones and tablets utilize a central software repository in which software is curated and made available. The Android platform has Google Play, Apple has its App Store, and so on. For those that have used Linux for a while, this concept isn’t new. The concept of software repositories is similar to that of app stores and has been around within the Linux community since long before cellular phones even had color screens.

Linux has had package management since the ‘90s, initially popularized by Debian and then Red Hat. Software repositories are generally made available in the form of mirrors, to which your server subscribes. Mirrors are available across a multitude of geographic areas, so, typically, your installation of Ubuntu Server would...

Understanding the differences between Debian and Snap packages

Now, before we get into the ins and outs of managing packages, there are actually two completely different types of packages available to you, and you should understand the differences between them. As of the time of writing, we’re at a kind of crossroads regarding the way in which software is managed in Linux.

Traditionally, each distribution has its own package format and its own utilities to manage them. Ubuntu utilizes Debian packages (with package names ending in .deb) as the main package format, which Ubuntu inherits from the Debian distribution (Ubuntu is forked from Debian, which means that it uses Debian as a foundation). Ubuntu and Debian utilize the apt and dpkg commands to manage packages. On the other hand, distributions such as CentOS and Red Hat use RPM packages for their distributions, and the dnf command to manage them. There are other distributions and package formats as well, but for this...

Installing and removing software

Before we begin, we will want to research a bit regarding the application we want to install. In Ubuntu, there are multiple ways of installing software, so the best way to find out how to get started is by simply checking the documentation on the website for the application we want to install. Typically, a Google search will do (just make sure you check the domain and are on the correct site). Most software will have installation instructions for various platforms, including Ubuntu. Most of the time, it will just tell you to download the Debian package format via the apt install command. Other times, the software may have a Snap available, or even a PPA repository (we’ll discuss PPA repositories later on in this chapter). Let’s start our package management journey by taking a look at the apt commands that are used to install Debian packages.

Managing Debian packages with apt

APT, or Advanced Package Tool, is a suite of tools that...

Searching for packages

Unfortunately, the naming conventions used for packages in Ubuntu Server aren’t always obvious. Worse, package names are often very different from one distribution to another even for the same piece of software. While this book and other tutorials online will outline the exact steps needed to install software, if you’re ever on your own, it really doesn’t help much if you don’t know the name of the package you want to install. In this section, I’ll try to take some of the mystery out of searching for packages.

In the previous section, we went over searching for Snap packages, so I won’t repeat that here. The APT suite of utilities also has a means of searching for packages as well, which is the apt search command. We can use the following command to search for packages, by providing a keyword:

apt search <search term>

The output from this command will show a list of packages that match your search...

Managing package repositories

Often, the repositories that come pre-installed with Ubuntu will suffice for the majority of the Debian packages you’ll install via APT. Every now and then, though, you may need to install an additional repository in order to take advantage of software not normally provided by Ubuntu, or versions of packages newer than what you would normally have available. Adding additional repositories allows you to subscribe to additional sources of software and install packages from them in the same way as you would from any other source.

Adding additional repositories should be considered a last resort, however. When you install an additional repository, you’re effectively trusting the author of that repository with your organization’s server. Although I haven’t ever seen this happen first-hand, it’s theoretically possible for authors of software to include back doors or malware in software packages (intentionally or unintentionally...

Backing up and restoring Debian packages

As you maintain your server, your list of installed packages will grow. If, for some reason, you needed to rebuild your server, you would need to reproduce exactly what you had installed before, which can be a pain. It’s always recommended that you document all changes made to your server via a change control process, but, at the very least, keeping track of which packages are installed is an absolute must. In some cases, a server may only include one or two extra packages in order to meet its goal, but, in other cases, you may need an exact combination of software and libraries in order to get things working like they were. Thankfully, the dpkg command allows us to export and import a list of packages to install.

To export a list of installed packages, we can use the following command:

dpkg --get-selections > packages.list

This command will dump a list of package selections to a standard text file. If you open it, you...

Cleaning up orphaned apt packages

As you manage packages on your server, you’ll eventually run into a situation where you’ll have packages on your system that are installed but not needed by anything. This occurs either when removing a package that has dependencies, or when the dependencies on an installed package change. As you’ll remember, when you install a package that requires other packages, those dependencies are also installed. But if you remove the package that required them, the dependencies will not be removed automatically.

To illustrate this situation, if I remove the apache2 package from one of my servers, I will see the following extra information if I then try to install something else:

Figure 3.5: Output with orphaned packages shown

In this example, I removed apache2 (that was done before the screenshot was taken), then I went on to install tmux. The package I was trying to install is arbitrary; the important part is the text...

Taking advantage of hardware enablement updates

One issue in the Linux industry has been hardware support. This is problematic in various Linux distributions because you may find yourself in a situation where you’re using a server (or even a desktop or laptop) that was released with the latest processor and chipset, but no newer version of your Linux distribution has been released yet that includes updated drivers that support it. Unlike platforms such as Windows, hardware drivers are typically built right into the Linux kernel. So, if you have an old release (which would contain an older kernel), you might be out of luck for hardware support until the next version of your Linux distribution is released.

Thankfully, Ubuntu has come up with a system to address this problem, and it’s one of the many things that set it apart from other distributions. Ubuntu features a set of updates known as the hardware enablement (HWE) stack, which is an exclusive feature of long...

Summary

In this chapter, we have taken a crash course in the world of package management. As you can see, Ubuntu Server offers an amazing number of software packages and various tools that we can use to manage them. We began the chapter with a discussion of how package management with Ubuntu works, then we worked through installing packages, searching for packages, and managing repositories. Snap packages were also covered, which is a newer technology that aims to enhance software distribution on Ubuntu.

In Chapter 4, Navigating and Essential Commands, we’ll take a look at foundational commands for navigating the Linux Shell, understanding the filesystem layout, and more.

Relevant video

Further reading

Join our community on Discord

Join our community’s Discord space for discussions with the author and other readers:

https://packt.link/LWaZ0

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Ubuntu Server - Fourth Edition
Published in: Sep 2022Publisher: PacktISBN-13: 9781803234243
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Jay LaCroix

Jeremy "Jay" LaCroix is a technologist and open-source enthusiast, specializing in Linux. He has a net field experience of 20 years across different firms as a Solutions Architect and holds a master's degree in Information Systems Technology Management from Capella University. In addition, Jay also has an active Linux-focused YouTube channel with over 250K followers and over 20M views, available at LearnLinuxTV, where he posts instructional tutorial videos and other Linux-related content. He has also written Linux Mint Essentials and Mastering Linux Network Administration, published by Packt Publishing.
Read more about Jay LaCroix