Mastering Linux System Administration. Richard Blum
Чтение книги онлайн.
Читать онлайн книгу Mastering Linux System Administration - Richard Blum страница 24
The package management system utilities and their associated commands are vastly different between the various Linux distributions. The two primary package management system base utilities commonly used in the Linux world are dpkg and rpm.
Debian‐based distributions such as Ubuntu use, at the base of their package management system utilities, the dpkg
command. This command interacts directly with the package management system on the Linux system and is used for installing, managing, and removing software packages.
The Red Hat–based distributions, such as CentOS, use the rpm
command at the base of their package management system. Similar to the dpkg
command, the rpm
command can list installed packages, install new packages, and remove existing software.
Note that these two commands are the core of their respective package management system, not the entire package management system itself. Many Linux distributions that use the dpkg
or rpm
methods have built additional specialty package management system utilities upon these base commands to make your life much easier. The following sections walk through the package management systems you'll find in Debian‐based systems, such as Ubuntu. Chapter 5, “Installing and Maintaining Software in Red Hat,” covers using the rpm package management system.
Inspecting the Debian‐Based Systems
The dpkg
command is at the core of the Debian‐based family of package management system tools. It provides options to install, update, and remove Debian package files on your Linux system.
The dpkg
command assumes you have the package file either downloaded onto your local Linux system or available as a URL. More often than not, that isn't the case. Usually you'll want to install an application package from the repository for your Linux distribution. To do that, you'll use the Advanced Package Tool (APT) suite of tools.
apt‐cache
apt‐get
apt
The apt
command is essentially a front end for both the apt‐cache
and apt‐get
commands. The nice thing about APT is that you don't need to remember which tool to use when—it covers everything you need to do with package management. The basic format for the apt
command is
apt [options] command
The command defines the action for apt
to take. If needed, you can specify one or more options to fine‐tune what happens. This section looks at how to use the APT command‐line tool to work with the software packages on your Linux system.
Managing Packages with apt
A common task that Linux system administrators face is to determine what packages are already installed on the system. The apt list
command displays all the packages available in the repository, but by adding the ‐‐installed
option, you can limit the output to only those packages already installed on your system.
$ apt --installed list Listing… accountsservice/focal-updates,focal-security,now 0.6.55-0ubuntu12~20.04.4 amd64 [installed,automatic] adduser/focal,now 3.118ubuntu2 all [installed,automatic] alsa-topology-conf/focal,now 1.2.2-1 all [installed,automatic] alsa-ucm-conf/focal-updates,now 1.2.2-1ubuntu0.4 all [installed,automatic] amd64-microcode/focal,now 3.20191218.1ubuntu1 amd64 [installed,automatic] apparmor/focal-updates,now 2.13.3-7ubuntu5.1 amd64 [installed,automatic] apport-symptoms/focal,now 0.23 all [installed,automatic] apport/focal-updates,focal-security,now 2.20.11-0ubuntu27.12 all [installed,automatic] … $
As you can guess, the list of installed packages will be long, so we've abbreviated the output to show just a sample of what the output looks like. Next to the package name is additional information about the package, such as the version name, and whether the package is installed and flagged for automatic upgrades.
If you already know the package name and want to quickly display detailed information about it, use the show
command.
apt show package_name
Here's an example of displaying the details of the package zsh
:
$ apt show zsh Package: zsh Version: 5.8-3ubuntu1 Priority: optional Section: shells Origin: Ubuntu Maintainer: Ubuntu Developers <[email protected]> Original-Maintainer: Debian Zsh Maintainers <[email protected]> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 2,390 kB Depends: zsh-common (= 5.8-3ubuntu1), libc6 (>= 2.29), libcap2 (>= 1:2.10), libtinfo6 (>= 6) Recommends: libgdbm6 (>= 1.16), libncursesw6 (>= 6), libpcre3 Suggests: zsh-doc Homepage: https://www.zsh.org/ Download-Size: 707 kB APT-Sources: http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages Description: shell with lots of features Zsh is a UNIX command interpreter (shell) usable as an interactive login shell and as a shell script command processor. Of the standard shells, zsh most closely resembles ksh but includes many enhancements. Zsh has command-line editing, built-in spelling correction, programmable command completion, shell functions (with autoloading), a history mechanism, and a host of other features. $
The apt show
command does not indicate that the package is installed on the system. It shows only detailed package information from the software repository. One detail you cannot get with apt
is a listing of all the files associated with a particular software package. To get this list, you will need to go to the dpkg
command itself.
dpkg -L package_name
Here's an example of using dpkg
to list all the files installed as part of the apt‐utils
package:
$ dpkg -L apt-utils /. /usr /usr/bin /usr/bin/apt-extracttemplates /usr/bin/apt-ftparchive /usr/bin/apt-sortpkgs /usr/lib /usr/lib/apt /usr/lib/apt/planners /usr/lib/apt/planners/apt /usr/lib/apt/solvers /usr/lib/apt/solvers/apt … $
You can also do the reverse—find what package a particular file belongs to, as shown here:
dpkg --search absolute_file_name
Note that you need to use an absolute file reference for this to work.
$ dpkg --search /usr/bin/apt-ftparchive apt-utils: /usr/bin/apt-ftparchive $
The output shows the apt‐ftparchive
file was installed as part of the apt‐utils
package.
Installing Software Packages with apt
Now that you know more about listing software package information on your system, this section walks you through a software package installation. First, you'll want to determine the package name to install. How do you find a particular software package? Use apt
with the search
command.
apt search package_name
The beauty of the search
command is that you do not need to insert wildcards around package_name
. Wildcards are implied. By default, the search command displays packages that contain the search term in either the package name or the package description, which can be misleading at times. If you want to limit the output to only package names, include the ‐‐names‐only