Practice: Debian package management

Solutions for setting up your Linux system and software

Return to exercises

Solution for exercise 1. Determining whether a package is installed

If you're not certain whether a package is installed, you can use the -l (that's a lowercase letter L) option to dpkg along with the package's name to find out:

$ dpkg -l zsh
No packages found matching zsh.

This response indicates that zsh is not installed. (If zsh is installed on your system, you could try another package or skip ahead to Uninstall a package, and then come back to the rest of the exercises.)

Solution for exercise 2. Search for packages

You can use the apt-cache command and its search subcommand to search for a package called zsh, as shown in Listing 1.

Listing 1. Using apt-cache to search for zsh
$ apt-cache search zsh
kdesdk-scripts - scripts and data files for development
zsh - A shell with lots of features
zsh-dbg - A shell with lots of features (debugging symbols)
zsh-dev - A shell with lots of features (development files)
zsh-doc - zsh documentation - info/HTML format
csh - Shell with C-like syntax, standard login shell on BSD systems
draai - A command-line music player for MPD
fatrat-czshare - fatrat plugin allowing download and upload to czshare
grml-shlib - Generic shell library used in grml scripts
tucan - Download and upload manager for 1-Click Hosters
viewglob - A graphical display of directories referenced at the shell prompt
zsh-beta - A shell with lots of features (dev tree)
zsh-beta-doc - zsh beta documentation - info/HTML format
zsh-lovers - tips, tricks and examples for the zsh
zsh-static - A shell with lots of features (static link)
zshdb - debugger for Z-Shell scripts

This output identifies several packages that are associated, in one way or another, with the string zsh. If you want to install the Z shell, the zsh package is clearly the one you want. (You might also want to install zsh-doc and perhaps others, too; but for now, just stick with zsh.)

Solution for exercise 3. Install a package with APT

To install a package from an APT repository, use apt-get and its install option, as Listing 2 shows.

Listing 2. Installing zsh with APT
$ sudo apt-get install zsh
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  zsh-doc
The following NEW packages will be installed:
  zsh
0 upgraded, 1 newly installed, 0 to remove and 59 not upgraded.
Need to get 4,504 kB of archives.
After this operation, 14.1 MB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ natty/main zsh amd64
4.3.11-4ubuntu2.is.3ubuntu1 [4,504 kB]
Fetched 4,504 kB in 7s (643 kB/s)                                              
Selecting previously deselected package zsh.
(Reading database ... 146971 files and directories currently installed.)
Unpacking zsh (from .../zsh_4.3.11-4ubuntu2.is.3ubuntu1_amd64.deb) ...
Processing triggers for menu ...
Processing triggers for man-db ...
Setting up zsh (4.3.11-4ubuntu2.is.3ubuntu1) ...
update-alternatives: using /bin/zsh4 to provide /bin/zsh (zsh) in auto mode.
update-alternatives: using /bin/zsh4 to provide /bin/rzsh (rzsh) in auto mode.
update-alternatives: using /bin/zsh4 to provide /bin/ksh (ksh) in auto mode.
Processing triggers for menu ...

Note: Because of Ubuntu's security model, commands that affect package installations must be preceded with the sudo command. On some distributions, or if you modify Ubuntu's default security model, you would omit sudo but execute the command from a root login.

The apt-get install command searches for and installs zsh. If it had any dependencies that were not installed, this command would also install them.

Solution for exercise 4. Determine a package's status

Verify that zsh has been installed by using the -s or --status option to dpkg, which displays status information on the package. Listing 3 shows the code.

Listing 3. Verify that zsh is installed
$ dpkg -s zsh
Package: zsh
Status: install ok installed
Priority: optional
Section: shells
Installed-Size: 13732
Maintainer: Ubuntu Developers (ubuntu-devel-discuss@lists.ubuntu.com)
Architecture: amd64
Version: 4.3.11-4ubuntu2.is.3ubuntu1
Depends: libc6 (>= 2.4), libcap2 (>= 2.10), libncursesw5 (>= 5.6+20070908)
Recommends: libc6 (>= 2.11), libpcre3 (>= 8.10)
Suggests: zsh-doc
Conffiles:
 /etc/zsh/zlogin 48032df2ace0977f2491b016e3c421a3
 /etc/zsh/zlogout b73789c3e790b855302ce10ca076037a
 /etc/zsh/zprofile 58c4f65d775c055b5d80b67c1bd12838
 /etc/zsh/zshenv 5a8a0ff4f6ff945a5aa6ba7f6f1e8c97
 /etc/zsh/zshrc e069ba51ba293da1aeddd5779324df19
 /etc/zsh/newuser.zshrc.recommended dac3563a2ddd13e8027b1861d415f3d4
Description: A 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.
Homepage: http://www.zsh.org/
Original-Maintainer: Debian Zsh Maintainers (pkg-zsh-devel@lists.alioth.debian.org)

This package is now installed, and you can see information on its version, its dependencies, who created it, and so on.

Solution for exercise 5. Identify files associated with a package

To learn which files were installed as part of the zsh package, use the -L option to dpkg:

$ dpkg -L zsh

The resulting output is quite lengthy, because the package includes many individual files. If you wanted to search for a particular file, you might want to pipe the output through grep or less.

Solution for exercise 6. Uninstall a package

For the final exercise, uninstall zsh (unless you want to try it and perhaps even use it regularly). To do so, use apt-get and its remove or purge command. Listing 4 shows the code.

Listing 4. Uninstalling zsh
$ sudo apt-get remove zsh
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  zsh
0 upgraded, 0 newly installed, 1 to remove and 59 not upgraded.
After this operation, 14.1 MB disk space will be freed.
Do you want to continue [Y/n]? y
(Reading database ... 148096 files and directories currently installed.)
Removing zsh ...
Processing triggers for man-db ...
Processing triggers for menu ...

Alternatively, you could use dpkg and its -r/--remove or -P/--purge option. Listing 5 shows the code.

Listing 5. Uninstalling zsh using dpkg
$ sudo dpkg -P zsh
(Reading database ... 148096 files and directories currently installed.)
Removing zsh ...
Purging configuration files for zsh ...
Processing triggers for man-db ...
Processing triggers for menu ...

In both cases, the Purge operation removes the package and its configuration files, whereas the Remove operation leaves the configuration files behind.

Alternate solutions: Synaptic

It's possible to use graphical user interface (GUI) tools such as Synaptic (shown in Figure 1) to perform any of these tasks. Such operations tend to be fairly intuitive. The LPI exam doesn't cover Synaptic, but it's sometimes more convenient than the text-mode tools, particularly when you're searching for packages or installing multiple packages.

Figure 1. You can perform package management tasks using GUI tools such as Synaptic
Synaptic, shown in this image, provides a point-and-click interface for package management

Return to exercises