Book Image

Troubleshooting Ubuntu Server

By : Skanda Bhargav
Book Image

Troubleshooting Ubuntu Server

By: Skanda Bhargav

Overview of this book

Table of Contents (16 chapters)
Troubleshooting Ubuntu Server
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Using dpkg for package management


Debian systems have dpkg as their underlying fundamental package management tool. dpkg can be used to install, uninstall, and build packages. One of the important points we need to remember is dpkg cannot download packages and its dependencies. The user has to take care of the dependencies and install them manually. dpkg can install the locally available packages. Let's now see some of the operations that dpkg can perform on an Ubuntu Server machine.

Use the following command to list the software already installed on your server machine:

dpkg –l

This command can generate a large output on your command line, depending upon the installed packages in the server machine, as shown in the following screenshot:

To list out a specific package, use the following command:

dpkg –l | grep apt

This will list out the packages with the name apt occurring in any of the installed packages. A sample output is shown here:

Here, we can see all of the installed packages in the server containing the word apt as whole or part of it in name of the packages that are installed in this server machine.

Another alternative to check whether a specific package is installed or not is to use the dpkg command with the -l option along with the package name. Let's check for the apt package:

dpkg -l apt

The output of this command is shown in the following screenshot. The letters ii at the start indicate the package is installed. The first letter that you see in the output before the name of the package is the desired status: i stands for installed and p stands for purged. The actual status is shown in the second letter. n stands for not installed and i in second place tells us the package is installed. This command also displays the version, architecture, and description, along with the name of the package.

Running dpkg without any arguments or parameters will show the error in the following screenshot. It requests the user to enter any of the options as arguments with dpkg:

dpkg

If you want to check which files a particular package has installed, use the following command with parameter -L and then the package name (here, apt-utils):

dpkg –L apt-utils

The output is shown in the following screenshot:

We listed all the files that the package apt-utils has installed in the machine. As you may see, it gives the absolute path of each file associated with the apt-utils package.

If you are unsure which package a particular file belongs to, you can use the dpkg command along with the optional -S parameter. The following command lists out the packages that are using this particular file:

dpkg -S /etc/logrotate.d

The output is as follows:

We see all the packages that are using /etc/logrotate.d in the preceding output. Let's crosscheck for one of the packages:

dpkg -L apport

The output is as follows:

In some cases, running dpkg -S may not be able to get the package name that uses a particular file. This is because many files are automatically generated during a package installation that dpkg may not be aware of.

To install a .deb package using dpkg, use the following command:

dpkg –i $package_name

Replace $package_name with the actual package you want to install. This will start the installation of the package. Please note that installation of software requires administrative access. So, use the dpkg command with the prefix sudo when installing or removing a package. Hence, this command will now become:

sudo dpkg –i $package_name

Let's now try to remove a package using the dpkg command. Use the option -r with the package name to remove a package. Here, we are removing the byobu package. However, it is recommended you do not use the dpkg tool to remove packages. It generally does not go well as dpkg does not handle dependencies, so it is possible that you may remove a package that is a dependency for some other package and the latter will become unstable or unusable. There are better alternative package management tools such as apt-get and aptitude that can be used for removal of packages, as they handle the dependencies well. We will cover the apt-get and aptitude tools next. The command to remove a package is as follows:

sudo dpkg –r byobu

As we can see in the following screenshot, when trying to remove a package without the sudo prefix, the system did not allow. After prefacing the command with sudo, we were successfully able to remove the byobu package from the server:

The command dpkg -P stands for purge. Configuration files are also removed along with the package when you run this command.

To view all the options dpkg supports, use the following command:

man dpkg