Installing Software on Debian Based Systems

Start course
Overview
Difficulty
Intermediate
Duration
2h 10m
Students
17
Description

As the title suggests, this course looks at intermediate-level skills for those who already know a bit about Linux but want to enhance that knowledge. In this course, we build upon some of the topics covered in our Linux Fundamentals course, including files and shell scripting, but also introduce new concepts such as wildcards, job control, switching users, and installing software. 

This course is part of the Linux Administration Bootcamp learning path, designed to get you up and running with Linux.

Learning Objectives

  • Learn what wildcards are and how and when to use them
  • Understand input, output, and redirection
  • Work with files and shell scripting
  • Implement processes and job control, and switch between users
  • Install software using RPM- and Debian-based systems

Intended Audience

  • Anyone with basic knowledge of Linux who wants to learn more
  • Professionals who want to learn more about Linux to enhance their career prospects

Prerequisites

This is an intermediate-level course so some knowledge of Linux is expected. If you're just starting out, then try our Linux Fundamentals course first.

Transcript

Now let's take a look at Debian based distributions. Here on your screen you see a couple of examples of Debian based distributions. Of course, Debian is Debian based Ubuntu, Linux Mint, Kali Linux, and Solon. These Debian based distributions use a package manager called APT. APT stands for the Advanced Packaging Tool. Historically APT was comprised of a few small utilities with the two most commonly used ones being apt-cache, and apt-get, however a few are using the latest versions of Debian and Debian based distros such as Ubuntu.

All the functionality of those different tools have been combined into one command, the apt command, and we'll cover that command in just a minute. However, if you find that the apt command isn't available I want to cover the slightly older method here of managing software with APT. And don't worry everything you learn here actually carries over to the apt command as you'll see shortly. If you want to search for a package by its name or description, use apt-cash search string where string is the thing that you are searching for.

To install a package use apt-get install package where package is the name of the package. By the way you can use the [-y] option to automatically answer yes to apt-gets questions. To remove a package use apt-get remove, follow it by the package name. Now be aware that this command does not delete the configuration files for that package from your system. If you want to remove both the package and its configuration files from the system you use apt-get purge followed by the package name.

To display information about a package use apt-cache show followed by the package name. APT keeps a local copy of available packages that are in the configured repositories. As new versions of software are released, this local copy will become stale or out of date. To get the current list of available software run apt-get update, before you install software it's a best practice to run apt-get update first. If you don't run apt-get update you might encounter a situation where the specific package you are attempting to install is not available.

Let's say the last time you ran apt-get update was two weeks ago, at that time let's also say that NGINX-1.18 was available to be installed. However, since then a bug was fixed and version 1.19 replaced version 1.18. If you try to install NGINX without running apt-get update, your local system will attempt to download the old version which is no longer available, and you'll get an error. By running apt-get update first, your local system will download a list of all the current packages and versions available. So when you're installing software on Debian based systems it's best to get in the habit of running apt-get update before performing the actual software installation.

If you wanna make sure that your system has all of the latest packages installed with all the latest bug fixes and security updates run apt-get upgrade. On newer distributions such as Debian 8 and later, and Ubuntu 16.04 and later we can use the apt command instead of apt-cache and apt-get. The APT program combines the functionality of apt-cache and apt-get. You can easily use what you've learned on the previous slide so instead of running apt-cache search you can simply run apt search instead. Also instead of running app-get install you would just run apt install. In addition to the apt utilities you can use the dpkg command to install packages.

Although APT handles dependencies on Debian based systems, the dpkg command does not. To list all the installed packages run dpkg-l. Use dpkg-S followed by a path to a file to list the package that contains the file at that specified path. If you want to list all the files that belong to a given package run dpkg-L followed by the package name. To install a package use dpkg -i followed by the file name that contains the package that you want to install. To remove or uninstall a package you use dpkg -r the package name.

So I'm going to do a quick demonstration here on an Ubuntu system. And these commands will work the same, be it on Ubuntu or Debian or other Debian based distributions. By the way, my system here has a connection to the internet because I'm going to be downloading packages from the internet. Now, remember that installing and uninstalling software requires root privileges. So we'll first switch to the root user. Next we want to make sure that we have the current list of available packages that are in the remote repositories. So let's go ahead and run apt update.

Now that we have an updated list of packages that we can install, let's search for the one that we're interested in. And in this example, we'll install the NGINX web server. Okay great, so you can see that there are several packages that have scrolled by on our screen. And I'm just gonna scroll up here and see if there is an NGINX package. And sure enough, there is an NGINX package. The description of the NGINX package is a small, powerful, scalable web and proxy server. So that sounds like what we're looking for.

So let's go ahead and install that NGINX package now with apt install and I'm going to use the -y option to automatically answer yes to any of APT's questions. And that question would be, "Hey, do you want to install this package along with its dependencies?" And so that's what -y will allow us to do. And then we'll give it a package name again, in this case we're installing NGINX. Again, this is just a demonstration and I don't really need the NGINX web server. So let's go ahead and uninstall it now.

So one way to do that would be to use the apt remove command. But what we're going to do is use apt purge to remove not only the binaries for the NGINX web server but also the configuration files for that service as well. If you wanna make sure that your system has all of the latest packages installed that contain all the latest bug fixes and security updates, just run apt upgrade. So this system is fairly updated and it looks like there are only three packages that need to be upgraded. So if there are outdated packages, like there are here, APT will provide a list of those packages to you. And if you want to upgrade them go ahead and type y and hit enter. By the way, you can also use the -y option here too.

So if you want to force an update without reviewing the packages, run apt upgrade -y. Also if all of the installed packages are at the latest available versions already APT will report that there's nothing for it to do. Next, let's take a look at using the dpkg command. We can find a .deb package from the internet, download it, and then install it using the dpkg command. Just like with RPM packages when searching for deb packages on the internet your machine's operating system and processor architecture often matter. If you are using a 64 bit Intel processor you will look for packages that contain AMD64 in their names.

On the other hand, if you are using an ARM processor you'll look for ARM64 packages. However, if you see all, A-L-L in a deb package name that means it will work on all CPU architectures. As a reminder you can use the uname -m command to determine the architecture for your system. The output here indicates that the processor on this particular system is an ARM processor. So what I'm going to do is download a package from the internet to my local Linux system by using the curl command.

Now curl is mainly used to transfer data over a network such as downloading a file. The dash capital O option causes the file to be saved locally with the same name that was used on the remote system. Now let's attempt to install it with dpkg. This package has a dependency of example -libs, so we'll have to download and install that first. Now by using this low-level dpkg command we have to do our own dependency management. Now let's install the dependency first.

All right, so now let's go back and try to install our original package again. By the way don't think I'm a super fast typer, what I'm using here is tab completion. So I typed out example_ and just hit tab, and let Bash complete the file name for me. And then I hit enter. So I didn't have to type all those extra characters. Anyway, let's go ahead and search for the package that we just installed. Okay. It's listed as being installed. We can also list all the files that are owned by that package with dpkg-L followed by the package name.

By the way, if you are curious about a command and want to know more about it, and some more of the things it can do, you can almost always use --help after the command name. So for example, you could use dpkg --help and hit enter, and you'll see all kinds of information about all the things you can do with the dpkg command. Let's go ahead and remove that package that we just installed with dpkg -r followed by the package name.

By the way, you might encounter a situation where you've removed a package or uninstalled a package but the dependencies that it used are still left on the system. And luckily APT has a way to deal with that. And that's by using apt autoremove and that command will remove all of the unused dependencies from your system. And that's the way to keep things clean on your system.

By the way, I don't think I mentioned this in the RPM and DNF lesson, but DNF also has the autoremove sub command to do the same thing. So on an RPM based distribution you can use dnf autoremove. And again, here on a Debian based distribution you can use apt autoremove. Let's go ahead and wrap things up. So packages are used to install software on Linux systems and you can manipulate packages with a package manager.

Two of the most popular package formats are RPM and DEB. for RPM based distributions use the dnf and rpm commands to manage those packages. For Debian based distributions use apt and dpkg. At this point, I'd like to encourage you to try installing software on your own. Use the same method you learned here in this lesson, start off by searching for a package. And if there are multiple choices you may need to view the details of the possible packages to narrow down your choice of which one to install.

Once you've determined the name of the package you want to install, go ahead and install it. Finally verify that the package was successfully installed. If you need an idea for something to install let me suggest the Apache web server or the MariaDB database server.

About the Author
Avatar
Jason Cannon
Founder, Linux Training Academy
Students
304
Courses
40
Learning Paths
4

Jason is the founder of the Linux Training Academy as well as the author of "Linux for Beginners" and "Command Line Kung Fu." He has over 20 years of professional Linux experience, having worked for industry leaders such as Hewlett-Packard, Xerox, UPS, FireEye, and Amazon.com. Nothing gives him more satisfaction than knowing he has helped thousands of IT professionals level up their careers through his many books and courses.

Covered Topics