Installing Ubuntu and Adding Software - Ubuntu Linux Toolbox: 1000+ Commands for Power Users (2013)

Ubuntu Linux Toolbox: 1000+ Commands for Power Users (2013)

Chapter 2

Installing Ubuntu and Adding Software

IN THIS CHAPTER

· Installing Ubuntu

· Working with software repositories

· Getting software with APT

· Managing software with Debian package tools

· Extracting files from other package formats

Time-tested tools for initially installing Ubuntu, and later adding and managing software, include the APT (Advanced Package Tool) and dpkg (Debian package) utilities. These are some of the standard packaging utilities that serve as a back end to the more familiar desktop GUI tools for managing software on Ubuntu and other Debian-based systems. These package utilities interact with .deb files from online repositories, or local .deb files you’ve downloaded and have sitting on your hard disk.

This chapter highlights critical issues you need to know during Ubuntu initial installation. It covers information about online Ubuntu software repositories. Detailed examples of APT, dpkg, tasksel, and related command line utilities including aptitude are given later in this chapter.

Obtaining and Installing Ubuntu

Ubuntu and its close cousins Kubuntu, Xubuntu, and Edubuntu are all designed with ease of use and familiarity in transition in mind. These distributions focus on keeping things simple and clean to help smooth out the learning curves when you are adapting to a new system.

The Ubuntu installer (Ubiquity) is a prelude to the simplicity of the Ubuntu system, breaking down the install process into about 10 clicks. With an Internet connection, you can download one of the ISO images for free from the Ubuntu download page (www.ubuntu.com/download). From the download page, you can choose if you want installation media for an Ubuntu desktop, server, or cloud system. Once you make your selection, you are offered the chance to download the latest version of Ubuntu or the most recent version of Ubuntu available for Long Term Support (LTS). For example:

· Ubuntu 12.10—Released in October 2012. The server version of this release is supported for 18 months (so support expires in April 2014).

· Ubuntu 12.04 (LTS)—Released in April 2012. Because it is a Long Term Support release, it comes with five years of guaranteed support (so it is supported until April 2017).

There are 64-bit and 32-bit versions of Ubuntu available when you choose Ubuntu Desktop, Ubuntu Server, or Cloud infrastructure from the Ubuntu Download page. The 64-bit version will not work if you have a standard x86 (32-bit) computer. The 32-bit version should work on a 64-bit machine, but not as efficiently. So choose the version that is right for your computer.

As you gain experience with Ubuntu, you can look into other ways of getting an installed Ubuntu system. Some of these methods, which are available from the Download page, include:

· Juju—With Juju, a system administrator can capture a deployed Ubuntu system and store it in what is referred to as charms. Those charms can then be used to reproduce the Ubuntu system and deploy it in various cloud environments.

· Cloud Guest—To just try Ubuntu in the cloud, you can select Cloud Guest. This allows you to try Ubuntu with some preconfigured applications in the cloud for one hour.

If you are fairly new to Ubuntu, however, I recommend downloading the appropriate installation media and installing it on an extra computer you have available. To do that, just select the version that matches your computer and download it.

After your download is complete, you may want to visit the HowToMD5SUM page and get the md5sum file for the version of Ubuntu you downloaded (https://help.ubuntu.com/community/HowToMD5SUM). This can help verify the integrity of the ISO image. Most open source software will have such a digital signature available, and I recommend that you verify this prior to installation, or before burning the ISO image to CD-ROM or DVD.

Note If you desire more security for your downloads beyond the MD5 Checksums, look at SecureApt. For more information on how APT uses digital authentication and encryption for software packages, visit the SecureApt section on the Ubuntu help website (https://help.ubuntu.com/community/SecureApt).

Preparing to Install

If you are going to erase everything on your computer’s hard disk and install Ubuntu, you don’t have to make preparations for your install in advance. If you want to keep any data from your hard disk, back up that data before proceeding. To keep existing data on your hard disk and add Ubuntu, you may need to resize existing disk partitions and repartition your disk. See Chapter 7 for information on disk resizing and partitioning commands.

Choosing Installation Options

To test the commands in this book, I use the 64-bit server installation of Ubuntu 12.04 (LTS). You may use other installation media versions, as you like. There should be relatively few differences with the commands shown in this book, regardless of whether you install a server or desktop system or even use a different release.

Note If you do choose a server install, keep in mind that it provides a minimal system, with the choice of adding a few services. Although there is no desktop software installed, you’ll have a chance to add desktop software later in this chapter with a variety of command line tools. If you prefer, you can simply start with a desktop install instead.

After booting from the Install CD, you are asked to choose the language to use. Then you are presented with a menu of options, as shown in the following list:

· Install Ubuntu Server—Begin the installation process immediately. (Choose this option.)MAAS stands for Metal as a Service. You could use this feature if you are setting up multiple servers and you want to deploy preconfigured systems. (Because you are installing a single server, don’t choose this option.)

· Check disc for defects—Test the CD for problems, reading the CD to find problems now instead of in the middle of the install.

· Test memory—If you suspect there are problems with your RAM, Ubuntu allows you to run Memtest86 (www.memtest.org/) to stress test your RAM to look for errors.

· Boot from first hard drive—If you’ve accidentally booted with the CD-ROM in the drive, simply pick this menu item to boot from your first hard drive.

· Rescue a broken system—The installation CD can also be used as a rescue CD. Use this if your Ubuntu system is unbootable and you want to get at the contents of your hard disk to fix the problem. (This selection is not used for a new installation.)

You can find out more about installing Ubuntu from the Installation guide for the particular installation type and version you are using. For example, for the Ubuntu 12.04 LTS server install, go to: https://help.ubuntu.com/12.04/serverguide/installation.html.

Answering Installation Questions

Most of the screens you see during Ubuntu installation are quite intuitive. The following list offers a quick review of those screens, along with tips where you might need some help:

· Install welcome—Select your language.

· Where are you?-—Select the country where you are located to help set your time zone. (Worldwide servers are sometimes set to GMT time.)

· Keyboard layout—You can press keys to have the installer detect the keyboard layout or select from a list of available keyboard layouts.

· Enter the hostname—Choose a single hostname to represent your system. For example, you would simply type abc if your full hostname was abc.example.com.

· Set up users and passwords—Add the full name for the user, a shorter username, and password. This user will have super-user privileges (the root account is not configured by default in Ubuntu). You are also asked if you want to encrypt your home directory. (This makes your data more secure from someone who steals your hard drive, but it makes it so that you must remember the password you used to encrypt the directory or make your home directory inaccessible to yourself as well.)

· Configure your clock—The installer attempts to contact a network time server to set your clock and suggests your time zone (based on your current location). You can choose the time zone it recommends or choose a different one. As mentioned, some server admins like to set time zones to GMT if you need to sync up servers that are used worldwide.

· Prepare disk space—Select Guided partitioning if you want Ubuntu to guess how to lay out the disk. Select Manual if you want to determine the partitions yourself. I recommend that you choose the guided setup with LVM. Also, if you don’t use all the space available, you can use the LVM commands later in Chapter 7 to grow and shrink your LVM partitions.

· Start the installation—Once partitioning completes, the installation begins.

You may be prompted during the installation process to:

· Configure a proxy server, if it is needed to reach Ubuntu software repositories to get the software needed to complete the installation.

· Choose whether or not to get automatic software updates.

· Select which software to install. (I simply added OpenSSH so I could remotely log in to the server. I’ll add others later.)

· Install the GRUB boot loader (install it to the Master Boot Record if you have no other operating systems installed).

While the installer is running, multiple terminal sessions are available via the Ctrl+Alt+F2 and Ctrl+Alt+F3 key combination if you just need a shell prompt. Also, as the install progresses, Ctrl+Alt+F4 will show any messages or errors encountered during this process. Use Ctrl+Alt+F1 to return to the installation screen.

Working with Debian Software Packages

If you prefer to use a GUI tool for installing software, the SynapticPackage Manager is available from the desktop or an ssh session using the -Xssh parameter to tunnel X11 (see Chapter 13). The aptitude utility provides a nice curses (text-based) front end to APT when run with no arguments. A front end for the dpkg utility, dselect, is also available on most Debian systems, but can be difficult to learn to operate.

Ubuntu uses the Debian package format (an ar archive, actually), which is a standard method for packaging software for Debian-based systems. By gathering software components in separate Debian packages (.deb extension) the software can not only carry a self-contained archive of the software, it can also hold lots of information about the contents of the package. This metadata can include software descriptions, dependencies, computer architecture, vendor, size, licensing, and other information.

When a basic Ubuntu system is installed, you can add, remove, and otherwise manage .deb files to suit how you use that system. Ubuntu, Kubuntu, Xubuntu, Edubuntu, and most other Debian-based systems will use .deb files to install the bulk of the software on the system. The aptitude tool should work very well for most day-to-day software needs; however, many other tools for managing these packages exist, and you may need to use some of them occasionally:

· APT—Use APT to download and install packages from online repositories. The APT commands (apt-get, apt-cache, and so on) can be used to install packages locally. However, it’s normally used for working with online software.

· dpkg—Use dpkgto work with .deb files from CD-ROM or other disk storage. The dpkg command has options for configuring, installing, and obtaining information on system software.

· aptitude—Use aptitude at the command line for working with online repositories. The aptitude tool is recommended as the first choice because it will automatically take care of some of the tasks you must do manually when working with dpkg or APT.

This chapter includes sections on each of these utilities, outlining the most appropriate circumstances for using each tool.

Note For more information on these package tools, consult the man pages for APT and dpkg.

Ubuntu (and the other *buntu offerings) are installed from a single CD-ROM or DVD. After installing, you can run the apt-cache stats command to report on the total number of packages available:

$ apt-cache stats

Total package names : 50267 (1,005 k)

Total package structures: 85142 (4,768 k)

Normal packages: 58468

...

As you can see, from a barebones stock Ubuntu install, over 50,000 pieces of software are available. The Debian community is very careful to include only software that is appropriate for redistribution.

Note The Debian Tutorial at www.debian.org/doc/manuals/debian-tutorial/ch-introduction.html points out:

“Although Debian believes in free software, there are cases where people want or need to put proprietary software on their machine. Whenever possible, Debian will support this; although proprietary software is not included in the main distribution, it is sometimes available on the FTP site in the non-free directory, and there are a growing number of packages whose sole job is to install proprietary software we are not allowed to distribute ourselves.”

The Canonical group holds Ubuntu to similar standards (www.ubuntu.com/community/ubuntustory/licensing), offering software in four categories: main, restricted, universe, and multiverse:

· main—Contains software that is freely distributable and supported by the Ubuntu team. Much of this software is installed when you install Ubuntu.

· restricted—Contains software that is common to many Linux systems, supported by the Ubuntu team, but may not be under a completely free license.

· universe—Contains a snapshot of nearly every piece of open source software available in the Linux world and available under licenses that may not be as free as the others. Software in this component is not guaranteed for security fixes or support.

· multiverse—Contains software that does not meet the free concept of software as it applies to the Ubuntu main component license policy. Software in this component is not supported in any way and it’s up to you to determine licensing validity.

Working with Software Packages

The following sections describe the basics of package management, explaining what goes on behind the scenes and how to install packages. Learning this is a necessary first step prior to moving on to other tools such as aptitude.

The dpkg command is very powerful for installing single deb packages, but will not sift through and install dependencies that are needed by different pieces of software, nor does it care about software repositories, such as the Ubuntu components mentioned previously. APT, on the other hand, will resolve and install dependencies and consult the configured repositories, but it is not used to install .deb files located on a hard drive or other local disk.

Several other Linux distributions also use packaging systems similar to APT. Red Hat-based/derived distributions (including Red Hat Enterprise Linux, CentOS, Fedora, and Mandriva) have tools such as yum, rpm, urpmi,and smartto manage software. Although these tools are quite different from the ones Ubuntu uses, the ideas are similar; a configuration file is set up to tell the packaging tool where online to find the latest software packages. The packaging tool then works in conjunction with an installer to get the software on the system.

This system of having an online package fetcher (so to speak) and a back-end packaging tool is a very powerful combination to resolve dependency issues, digitally authenticate software integrity, easily keep a system up-to-date, and allow distribution maintainers to distribute changes simply and on a large scale.

Handling Locale Error Messages

If you are working at the command line with Ubuntu, you may see a locale error message like one of these while trying to install packages:

perl: warning: Setting locale failed.

perl: warning: Please check that your locale settings:

locale: Cannot set LC_CTYPE to default locale: No such file/directory

This seems to be a problem related to the installed language settings, or something with internationalized encoding in general. One workaround you can use to keep things satisfied is to export the LC_ALL environment variable and set it the same as your LANG setting.

$ export LC_ALL="$LANG"

There are several other possible workarounds on the help sites, but this one will be the easiest to undo in case the cure causes more problems than the condition. It should also work regardless of what language you speak. Note that you will have to run this command every time you open a local or ssh shell. You can automate this task by placing the command in your ~/.bashrc file.

Enabling More Repositories for apt

In previous releases of Ubuntu, the multiverse, and universe repositories were not enabled by default. These repositories now come enabled by default with Ubuntu, so doing updates and searching for software will turn up many more options. One concern you may have, however, is that support, licensing, and patches may not be available for the universe and multiverse repositories. This could be a problem if you are considering an installation where you need to adhere to certain policies and procedures.

To disable the universe or multiverse repositories, open the file /etc/apt/sources.list in a text editor and comment out the lines that have multiverse or universe components enabled. You may want to initial the comments to make note of what you commented out, as shown by the #cn in the following examples:

#cn deb http://us.archive.ubuntu.com/ubuntu/ precise universe

#cn deb-src http://us.archive.ubuntu.com/ubuntu/ precise universe

#cn deb http://us.archive.ubuntu.com/ubuntu/ precise-updates universe

#cn deb-src http://us.archive.ubuntu.com/ubuntu/ precise-updates universe

#cn deb http://us.archive.ubuntu.com/ubuntu/ precise multiverse

#cn deb-src http://us.archive.ubuntu.com/ubuntu/ precise multiverse

#cn deb http://us.archive.ubuntu.com/ubuntu/ precise-updates multiverse

#cn deb-src http://us.archive.ubuntu.com/ubuntu/ precise-updates multiverse

Another reason to edit the /etc/apt/sources.list file is to add extra repositories that may be offered by individuals or companies. To edit this file, you must have root permissions:

$ sudo vi /etc/apt/sources.list

Insert a line starting with deb (for pre-built packages) or deb-src (for source packages), then the URL for the repository, along with the distribution (such as precise above), and the component descriptions (universe in the examples). Typically, you’ll describe components as contrib for contributed (that is, not from the Ubuntu project) and free or non-free. Normally, you should receive all this information from the site that offers the repository.

If you do add other third-party repositories, be sure to look into the authenticity of the entity offering the software before modifying your Linux system. Although it’s not a big problem with Linux these days, it is easy to add broken or malicious software to your system if you do not exercise care and reasonable caution.

Only use software from well-known sources, and always have a means to verify software you download prior to installing.

Adding Software Collections with tasksel

If you start with a minimal system install, as was illustrated in the “Obtaining and Installing Ubuntu” section of this chapter, you may find it convenient to add groups of packages to get an entire feature installed. This saves you from hunting around to get all the packages that are needed for a particular feature.

Note If you choose a software collection with tasksel, a large number of packages will be downloaded and installed. For example, when I installed the Ubuntu desktop with tasksel, more than 900 packages were downloaded and installed. The process took more than 30 minutes with a decent Internet connection. So, make sure you mean it before you select a package collection to install.

To run tasksel, simply type:

$ sudo tasksel

A menu of available software collections appears. If you don’t have a desktop interface installed on your system, you could choose from several different desktop interfaces. Use the arrow key to move to the collection you want, press the spacebar to select it (which adds an asterisk), press Tab to highlight the OK button, and press Enter to begin installing.

Here is an example of a basic Ubuntu desktop being selected:

[ ] Ubuntu LXDE Desktop

[*] Ubuntu desktop

[ ] Ubuntu desktop USB

After packages are downloaded and installed, you might be prompted to do additional configuration. In some cases, you might need to reboot your computer for the feature to take effect.

Managing Software with APT

Although features in dpkg and APT can work to complement each other, most of the time APT will suffice for any software you need to install, download, upgrade, check, or search for on any Debian-based system. When I refer to APT, I’m talking about a set of software management commands that include apt-get, apt-cache, apt-key, and others.

For a quick command line reference of APT capabilities, use the -hoption on the command line with any APT command that interests you. Some APT commands require super-user privileges, so they must be preceded by the sudocommand to function properly. The following gives some common uses of APT commands.

Note The aptitude utility is preferred over APT; however, in the interest of fundamentals, I will cover APT first.

· This command consults /etc/apt/sources.list and updates the database of available packages. Be sure to run this command whenever sources.list is changed:

$ sudo apt-get update

· This command does a case-insensitive search of the package database for the keyword given. The package names and descriptions are returned where that keyword is found:

$ apt-cache search keyword

· Download and install the given package name as found in the package database using the following command. Starting with APT version 0.6, this command will automatically verify package authenticity for GPG keys it knows about (http://wiki.debian.org/SecureApt):

$ sudo apt-get install package

· Download the package only, placing it in /var/cache/apt/archives, using the following command:

$ sudo apt-get -d install package

· Display information about the software from the named package with this command:

$ apt-cache show package

· Check updates for all installed packages and then prompt to download and install them with this command:

$ sudo apt-get upgrade

· This command updates the entire system to a new release, even if it means removing packages. (This is not the preferred method for updating a system.)

$ sudo apt-get dist-upgrade

· Run this command anytime to delete partially downloaded packages, or packages no longer installed:

$ sudo apt-get autoclean

· Remove all cached packages from /var/cache/apt/archives to free up disk space using this command:

$ sudo apt-get clean

· This command removes the named package and all its configuration files. Remove the --purge keyword to keep config files:

$ sudo apt-get --purge remove package

· This command does a sanity check for broken packages. This tries to fix any “unmet dependency” messages:

$ sudo apt-get -f install

· Print version information of installed APT utilities with this command:

$ apt-config -V

· This command lists GPG keys that APT knows about:

$ sudo apt-key list

· Print statistics on all packages installed with this command:

$ apt-cache stats

· Use this command to print dependencies for a package (whether it’s installed or not):

$ apt-cache depends

· List all packages installed on the system with this command:

$ apt-cache pkgnames

Finding Packages with APT

To find packages in any available repository, you can query for new software using the apt-cache command. For example, to search for the bzflag tank game, you could type the following:

$ apt-cache search bzflag

bzflag - a 3D first person tank battle game

bzflag-client - BZFlag client

bzflag-data - BZFlag data file

bzflag-server - bzfs - BZFlag game server

You can also ask APT to show info about the bzflag package:

$ apt-cache show bzflag

Package: bzflag

Priority: optional

Section: universe/games

Installed-Size: 212

Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>

Original-Maintainer: Tim Riker <Tim@Rikers.org>

...

Just how much extra software will bzflag require to be updated? Check for dependencies with the following:

$ apt-cache depends bzflag

Depends: bzflag-client

Depends: bzflag-server

...

Installing Packages with APT

Using sudo with APT or another package tool, you can install software available from any software repository you have enabled for Ubuntu. This shows bzflag being installed using APT:

$ sudo apt-get install bzflag

Reading package lists... Done

Building dependency tree

Reading state information... Done

The following extra packages will be installed:

bzflag-client bzflag-data bzflag-serverThe following NEW packages will be installed:

bzflag bzflag-client bzflag-data bzflag-server

0 upgraded, 4 newly installed, 0 to remove and 61 not upgraded.

Need to get 12.0 MB of archives.

After this operation, 19.4 MB of additional disk space will be used.

Do you want to continue [Y/n]? Y

...

Once the installation is done, provided you have a desktop installed, you can run the bzflag program by typing bzflag on the command line, or selecting it from the Games menu on the Ubuntu desktop.

Upgrading Packages with APT

Over time, packages change and new versions add neat new features and fix problems. You can use APT to upgrade your system to new versions following a two-step process.

First, check for updates to the packages your Ubuntu system knows about using the update option to apt-get:

$ sudo apt-get update

This command searches the repositories for new versions of packages available for downloading, and updates the list of packages and versions cached on your Ubuntu system.

Second, upgrade the packages on your Ubuntu system by using the upgrade option to apt-get:

$ sudo apt-get upgrade

You should always update the package list prior to upgrading packages, so it is a good idea to always run these commands together. Separate the commands with a semicolon to tell the shell to run them both, one after the other:

$ sudo apt-get update; sudo apt-get upgrade

Get:1 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main

base-files amd64 6.5ubuntu6.4 [69.9 kB]

Get:2 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main dpkg

amd64 1.16.1.2ubuntu7.1 [1,830 kB]

...

The following packages will be upgraded:

accountsservice apparmor apt apt-transport-https apt-utils

aptitude base-files

bind9-host busybox-initramfs busybox-static coreutils dbus dnsutils

dpkg gnupg gpgv

...

59 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.

Need to get 43.9 MB of archives.

After this operation, 569 kB of additional disk space will be used.

Do you want to continue [Y/n]? Y

Upgrading a Single Package with APT

Upgrading a single system package on Ubuntu is pretty straightforward using apt-get install <package>. You need to run this command with sudo to gain root permissions. The old version is automatically updated to the newest one available.

Note It may seem counterintuitive, but the upgrade option to apt-get upgrades all packages. The install option installs a new package or installs an upgrade to one or more specific packages.

First, check the version of the currently installed application. In this example, I assume that an earlier version of the minicom application, an application for communicating over serial lines, is installed on your system. Like most commands, the minicom program supports an option to display its current version number:

$ minicom --version

minicom version 2.2 (compiled Mar 7 2007)

...

Now use APT to install the latest version of the minicom package from the repositories. APT tells you that you are upgrading a package:

$ sudo apt-get install minicom

...

The following packages will be upgraded:

minicom

Now ask minicom for its version again and you can see it has indeed been upgraded:

$ minicom --version

minicom version 2.5 (compiled May 2 2011)

...

Removing Packages with APT

You can remove a package from your Ubuntu system by giving apt-get the remove option. You will be prompted to confirm before actually removing the software:

$ sudo apt-get remove bzflag

Reading package lists... Done

Building dependency tree

Reading state information... Done

...

The following packages will be REMOVED:

bzflag

0 upgraded, 0 newly installed, 1 to remove and 2 not upgraded.

After this operation, 217 kB disk space will be freed.

Do you want to continue [Y/n]? n

Cleaning Up Packages with APT

After your initial installation of an Ubuntu release, Ubuntu keeps downloaded packages cached in /var/cache/apt/ to speed up downloading if you ever need them again. Over time, this can use up a lot of disk space. You can remove this package cache, but you will need to download a removed package again at a later date if it is needed for dependencies. Clean up the cache by giving apt-get the clean option. I show how this works by first running the Linux find command on the /var/cache/apt/ directory to show the packages currently cached:

$ find /var/cache/apt/ -name \*.deb

/var/cache/apt/archives/nautilus_1%3a3.4.2-0ubuntu6_amd64.deb

/var/cache/apt/archives/gwibber-service-identica_3.4-0ubuntu2.1_all.deb

/var/cache/apt/archives/gir1.2-peas-1.0_1.2.0-1ubuntu1_amd64.deb

Now clean up all the packages cached in the APT cache directory, and then verify that they are removed by running the find command again:

$ sudo apt-get clean

$ find /var/cache/apt/ -name \*.deb

The directory is empty now.

Note If you’ve run the -h option with apt-get, you may have noticed that the Ubuntu version of APT has Super Cow Powers. You can find out more about these Powers by asking apt-get to moo.

Downloading Packages with APT

If you want to download a package from a software repository without installing it, you can use the download option to apt-get. Once downloaded, the package can be investigated with the dpkg command before you install it (as described in the next section). To download the minicom package to the current directory, type the following:

$ sudo apt-get download minicom

Managing Software with dpkg

The dpkg utility (and related commands) works at a layer lower than the APT utilities do. APT uses dpkg behind the scenes to manage software on your Ubuntu system. APT and dpkg work in much the same way that yum and rpm do on Red Hat-based Linux distributions. Usually, APT will have enough functionality to get you through just about anything, but there are times when dpkg will be needed, such as finding out which package is associated with a given file on your system. The following gives some common dpkg commands and operations.

Note dpkg uses the -D flag to signify debugging information to be printed while performing various operations. If you want more information than the default output, try -D1 with some of the dpkg commands. A section in the dpkg man page lists output levels for use with the -D flag.

· This command lists files that are installed by the .deb package file (replace whatever.deb with the name of the package you want to query). You must give the full or relative path to the .deb file:

$ dpkg -c whatever.deb

· This lists information about the .deb package file:

$ dpkg -I whatever.deb

· This lists information about the package:

$ dpkg -p whatever.deb

· List the packages where the given filename is found using this command. The filename can include a path to a file or just the name of a file:

$ dkpg -S filename

· This command lists all installed packages. This will also take options for more specific info:

$ dpkg -l

· This command lists all the files that have been installed from a package (the package must have been previously installed):

$ dpkg -L package

· The -s option lists the status of the given package:

$ dpkg -s package

· This installs the given .deb package file:

$ sudo dpkg -i whatever.deb

· This removes the given package from the system, but leaves configuration files behind. (That way, if the package is reinstalled later, it can resume using your configuration files.)

$ sudo dpkg -r package

· Removes package and configuration files of the given package.:

$ sudo dpkg -P package

· Extracts the files contained in the .deb package file to a destination directory. Note that this will reset permissions on the target directory or create the directory if it does not yet exist:

$ sudo dpkg -x whatever.deb /tmp/whatever

· Using the dpkg command, any user can query the package database. To use the command to install or remove software from your system, you must have root privileges.

Installing a Package with dpkg

The dpkg command focuses just on packages, while apt-get will take care of the messy details of finding out which repository hosts a package and downloading from there. For simplicity, the following example uses apt-get to download a package and then dpkg to install it, just to provide a flavor of the underlying dpkg command:

$ sudo apt-get download minicom

Get:1 Downloading minicom 2.5-2 [297 kB]

Fetched 297 kB in 0s (302 kB/s)

The command downloads the package to the current directory.

Now, install the .deb file using the command dpkg -i command (for install):

$ sudo dpkg -i /var/cache/apt/archives/minicom_2.5-2_amd64.deb

Selecting previously deselected package minicom.

(Reading database ... 185336 files and directories currently installed.)

Unpacking minicom (from .../minicom_2.5-2_amd64.deb) ...

Setting up minicom (2.5-2)

Processing triggers for man-db ...

Removing a Package with dpkg

To remove an installed package with dpkg, use the -r option as follows:

$ sudo dpkg -r minicom

(Reading database ... 185407 files and directories currently installed.)

Removing minicom

Processing triggers for man-db ...

If you want to remove the package and its configuration files all at once, or remove the config files after removing the package, use the following:

$ sudo dpkg -P minicom

(Reading database ... 185335 files and directories currently installed.)

Removing minicom ...

Purging configuration files for minicom ...

Extracting Files from a .deb File with dpkg

Debian and Ubuntu packages come bundled into single files, .deb files. Each .deb file contains one or more files that make up the package itself, such as a pre-built command, support files, documentation, and perhaps the source code.

So, a .deb file is basically an archive of files that you want to install to your computer, plus some header and control information that identifies the software (descriptions, Checksums, build information, and so on).

You can extract a lot of this information on a package with the dpkg command. This example extracts the files from the .deb file residing in the apt archives directory for the rsync package to a directory under /tmp:

$ mkdir /tmp/rsync_contents

$ sudo dpkg -x /var/cache/apt/archives/rsync_3.0.9-1ubuntu1_amd64.deb \

/tmp/rsync_contents

$ ls /tmp/rsync_contents/

etc lib usr

You can replace the file rsync_3.0.9-1ubuntu1_amd64.deb in the preceding command with any .deb file you download.

Querying Information about .deb Packages

The following example shows how to query installed packages for a package named rsync and display version information about that package:

$ dpkg -p rsync

...

Version: 3.0.9-1ubuntu1

· Use the -I option to get information about a .deb file in any directory:

· $ dpkg -I rsync_3.0.9-1ubuntu1_amd64.deb

· new debian package, version 2.0.

...

· To page through a list of all packages installed on your system, type the following:

· $ dpkg -l | less

· ...

· ii accountsservice 0.6.15-2ubuntu9.4 query and manipulate user acct info

...

· Or to just see a listing of a specific package use the -l option with a package name:

· $ dpkg -l rsync

· ...

ii rsync 3.0.9-1ubuntu1 fast, versatile, remote (and local) file-copyi

· Check a file on your system to see what package the file belongs to, if any:

· $ dpkg -S /usr/bin/rsync

rsync: /usr/bin/rsync

Now that you know how to select the package(s) you want to query, let’s get a little more information out of them. This example lists standard details about an installed package:

$ dpkg -s rsync

Package: rsync

Status: install ok installed

Priority: optional

Section: net

Installed-Size: 638

...

This lists the content of a .deb file in the local directory:

$ dpkg -c /var/cache/apt/archives/rsync_3.0.9-1ubuntu1_amd64.deb

drwxr-xr-x root/root 0 2011-11-08 14:05 ./

drwxr-xr-x root/root 0 2011-11-08 14:05 ./etc/

drwxr-xr-x root/root 0 2011-11-08 14:05 ./etc/default/

-rw-r--r-- root/root 1768 2011-11-08 14:05 ./etc/default/rsync

drwxr-xr-x root/root 0 2011-11-08 14:05 ./etc/init.d/

-rwxr-xr-x root/root 4395 2011-11-08 14:05 ./etc/init.d/rsync

...

This example extracts the control scripts inside a .deb file on disk to a destination directory. Use care when extracting as this command will reset the permissions on the target directory to 0755. (The 55 means that users other than you will have limited permissions on /tmp, and most applications assume they have wide open permissions to /tmp.) For this example, I’ll create the directory /tmp/my_$RANDOM (my_ and a random number) to work in:

$ cd /var/cache/apt/archives

$ sudo dpkg -e rsync_3.0.9-1ubuntu1_amd64.deb /tmp/my_$RANDOM

$ ls -lart /tmp/my_25445/

total 32

total 32

-rwxr-xr-x 1 root root 494 Nov 8 2011 prerm

-rwxr-xr-x 1 root root 113 Nov 8 2011 postrm

-rwxr-xr-x 1 root root 712 Nov 8 2011 postinst

-rw-r--r-- 1 root root 37 Nov 8 2011 conffiles

-rw-r--r-- 1 root root 1012 Nov 8 2011 control

-rw-r--r-- 1 root root 1743 Nov 8 2011 md5sums

To extract all the non-control files contained in the .deb file to a directory, use the -x option as follows (again, be aware that the directory permissions on the target directory will be reset to 0755):

$ sudo dpkg -x minicom_2.5-2_amd64.deb /tmp/dx_$RANDOM

$ ls -lart /tmp/dx_4921/

total 16

drwxr-xr-x 4 root root 4096 May 2 2011 usr

drwxr-xr-x 3 root root 4096 May 2 2011 etc

drwxr-xr-x 4 root root 4096 May 2 2011 .

drwxrwxrwt 15 root root 4096 Jan 27 22:03 ..

To see the installed files a package is using on the system, use the -L option:

$ dpkg -L minicom

/.

/usr

/usr/share

/usr/share/man

/usr/share/man/man1

/usr/share/man/man1/minicom.1.gz

/usr/share/man/man1/xminicom.1.gz

/usr/share/man/man1/ascii-xfr.1.gz

...

If the package is not removed completely, you may see some configuration files left over:

$ dpkg -L minicom

/etc

/etc/minicom

/etc/minicom/minicom.users

These examples cover some of the basic uses for dpkg, but by no means is this an exhaustive list. Other available options include those for reconfiguring packages (dpkg-reconfigure), telling dpkg what packages to ignore (dpkg hold), and setting selection states. Check the dpkg man page for more information.

Managing Software with aptitude

The dpkg and APT tools have been around for a long time and work well, but there are many nuances to both tools that can require a fair amount of understanding to use correctly. The aptitude tool tries to make things easier by automating some of the important package operations (such as running apt-get update before upgrading or installing) while allowing enough flexibility to be useful. For these reasons, I recommend the use of aptitude at the command line whenever possible.

The aptitude program aims to be both a curses application and command line tool. It is the command line usage I will focus on in this section. The following examples show a breakdown of ways to manage software packages with aptitude. Note that most of the options are similar to those of the apt-get command.

Note For more information on navigating the curses interface of aptitude, or other details, visit the Aptitude Survival Guide (https://help.ubuntu.com/community/AptitudeSurvivalGuide), or the Aptitude User’s Manual (http://people.debian.org/~dburrows/aptitude-doc/en/), or run man aptitude at the command line.

· Running aptitude with no options starts the curses interface. Use Ctrl+t to access the menu and the q key to quit:

$ sudo aptitude

· This lists help for aptitude usage:

$ aptitude help

· This lists packages matching the given keyword:

$ aptitude search keyword

· This command updates the available package indexes from the APT sources:

$ sudo aptitude update

· This upgrades all packages in use to their latest versions:

$ sudo aptitude upgrade

· List information about the given package, installed or not, with the following command:

$ aptitude show package

· This downloads the given package, but does not install it:

$ sudo aptitude download package

· This removes all downloaded .deb files from the /var/cache/apt/archives directory:

$ sudo aptitude clean

· This removes all outdated .deb files from the /var/cache/apt/archives directory. This maintains a current cache without filling up the disk:

$ sudo aptitude autoclean

· This installs the given package to the system. Note that there are several options for selecting specific versions and using wildcards:

$ sudo aptitude install package

· This removes the given package from the system:

$ sudo aptitude remove package

· This upgrades all packages to their most recent versions, removing or installing packages as necessary. The upgrade option is preferable to dist-upgrade:

$ sudo aptitude dist-upgrade

Updating and Upgrading Packages with aptitude

By default, aptitude will always perform an apt-get update before installing or upgrading. You can, however, still issue a command to perform only the update:

$ sudo aptitude update

Ign http://security.ubuntu.com precise-security InRelease

Hit http://security.ubuntu.com precise-security Release.gpg

Ign http://us.archive.ubuntu.com precise InRelease

...

If you want to upgrade all packages on the system, you can send along the upgrade option with aptitude. This will install any new packages waiting in the repositories (in this example, there were no new packages on hand):

$ sudo aptitude upgrade

Resolving dependencies...

The following NEW packages will be installed:

linux-image-3.2.0-36-generic{a}

The following packages will be upgraded:

linux-image-server linux-server

2 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded.

Need to get 38.5 MB of archives. After unpacking 149 MB will be used.

Do you want to continue? [Y/n/?] Y

Querying Information about Packages with aptitude

You can search with aptitude using keywords or full package names, just as with the other package tools. Here is a search using the word minic, which returns the minicom package and and xfce window manager plug-in:

$ aptitude search minic

i minicom - friendly menu driven serial communication program

$ aptitude show minicom

Package: minicom

State: not installed

Version: 2.5-2

Priority: optional

Section: universe/comm

...

Installing Packages with aptitude

You downloaded a package using apt-get before. Here you use aptitude to download a package without installing it:

$ sudo aptitude download minicom

...

Get:1 http://us.archive.ubuntu.com precise/main minicom 2.5-2 [297kB]

Fetched 276 kB in 0s (413 kB/s)

If you just want to install the minicom package, you can invoke aptitude like this:

$ sudo aptitude install minicom

...

Need to get 111 kB/408 kB of archives. After unpacking

1,503 kB will be used.

Do you want to continue? [Y/n/?] n

If there is a series of packages you want to install, you can give aptitude a wildcard to select with. Here, I install any package containing the word minic (as with the aptitude search shown above). This also selects all of the dependencies for each package using what aptitude calls a matcher. Use the ~n matcher, prefixed to your keyword, to install all packages containing the word minic:

$ sudo aptitude install "~nminic"

...

The following NEW packages will be automatically installed:

gcc-4.6-base:i386{a} libc6:i386{a} libcpan-mini-perl

libencode-locale-perl{a}

libfile-homedir-perl{a} libfile-listing-perl{a} libfile-which-perl{a}

0 packages upgraded, 37 newly installed, 0 to remove and 0 not upgraded.

Need to get 6,038 kB/6,335 kB of archives. After unpacking

18.1 MB will be used.

...

Accept this solution? [Y/n/q/?] n

Removing Packages with aptitude

Removing packages with aptitude is as easy as installing them. Just pass along the remove option:

$ sudo aptitude remove minicom

...

The following packages are unused and will be REMOVED:

lrzsz

The following packages will be REMOVED:

minicom

0 packages upgraded, 0 newly installed, 2 to remove and 0 not upgraded.

Need to get 0B of archives. After unpacking 1401kB will be freed.

Do you want to continue? [Y/n/?] Y

Cleaning Up Packages with aptitude

As you install things with aptitude, it will always download the .deb file and place it in the directory /var/cache/apt/archives. Over time, you will want to purge these files from the cache using the clean option, or at least the autoclean option to save disk space. If you look, you can see there are some files in the cache already:

$ ls /var/cache/apt/archives/

lock

lrzsz_0.12.21-5_amd64.deb

minicom_2.5-2_amd64.deb rsync_3.0.9-1ubuntu1_amd64.deb

partial

rsync_3.0.9-1ubuntu1_amd64.deb

Removing these with aptitude requires only that you use the clean or autoclean option:

$ sudo aptitude clean

Issuing the ls command again will show that the packages are indeed gone, so if you have a slow connection and it took you a week to download the last updates, you may want to think twice about this or use the autoclean option, which only removes outdated packages.

Useful Combinations of Options with aptitude

The -v option adds verbosity to aptitude operations. Used multiple times, you can get more than the usual information printed out as the operation executes. If you invoke aptitude with -v, it shows the MD5sum of the package. This is a digital fingerprint of sorts that can be used to test if the package has been tampered with or corrupted. Using -vv will offer up even more information:

$ aptitude show -vv minicom

Package: minicom

State: installed

...

Filename: pool/universe/m/minicom/minicom_2.5-2_amd64.deb

MD5sum: c2f4031b1fc6e688a783871cdca9890e

...

You can use the -s option with aptitude to tell it you want to simulate what would happen without actually performing the operation. This will work regardless of aptitude operation:

$ sudo aptitude -s install minicom

The following NEW packages will be installed:

...

Do you want to continue? [Y/n/?] y

Would download/install/remove packages.

Adding the -v option along with -s gives even more output:

$ sudo aptitude -vs install minicom

Reading package lists... Done

...

Do you want to continue? [Y/n/?] y

Inst lrzsz (0.12.21-5 Ubuntu:12.04/precise [amd64])

Inst minicom (2.5-2 Ubuntu:12.04/precise [amd64])

Conf lrzsz (0.12.21-5 Ubuntu:12.04/precise [amd64])

Conf minicom (2.5-2 Ubuntu:12.04/precise [amd64])

If you don’t want to be prompted to answer the question “Do you want to continue?” you can answer ahead of time by adding the -y option to your command:

$ sudo aptitude -vs -y install "~ninc"

Reading package lists... Done

Building dependency tree

Reading state information... Done

Reading extended state information

Initializing package states... Done

...

Be very careful with the -y option because there is no undo feature with aptitude.

Lastly, aptitude -h will return a reference of options that can be used if you need a refresher at any time. Interestingly enough, you can find out that the Ubuntu version of aptitude is lacking something:

$ aptitude -h

aptitude 0.6.6

...

This aptitude does not have Super Cow Powers.

No Super Cow Powers? I’m curious, so I ask aptitude to moo.

$ aptitude moo

There are no Easter Eggs in this program.

Easter eggs are items hidden in a program as a sort of surprise. Hmm. Maybe you can use the -v option for added verbosity:

$ aptitude -v moo

There really are no Easter Eggs in this program.

Maybe you need even more verbosity. Press aptitude for a little more information:

$ aptitude -vv moo

Didn't I already tell you that there are no Easter Eggs in this program?

Are you beginning to see a pattern here? Maybe adding more verbosity will lead somewhere.

Verifying Installed Packages with debsums

There are times when you will question the behavior of a binary or package installed on the system. It may not perform correctly, or may not even start at all. Problems with corrupt packages from unstable network connections or power outages do happen. In addition, malicious users may attempt to replace powerful commands with their own versions to cause further harm. It becomes useful to check the files on the filesystem against the information stored in the package.

The debsums program is a utility for Ubuntu and other Debian-based systems that checks the MD5 sums of every installed package against the md5sum files found in the /var/lib/dpkg/info directory.

You install this program with the following command:

$ sudo aptitude install debsums

Here are some of the most useful options for running debsums. See the man page for debsums to reveal all detailed information.

$ debsums -a Check all files, include config files left out by default

$ debsums -e Check config files for packages only

$ debsums -c List only changed files to stdout

$ debsums -l List files that don't have md5sum info

$ debsums -s List only errors; otherwise be silent

$ debsums package List the packages you want debsums to analyze

Note For many operations, you won’t need to run this utility as root (using sudo). Some files may not have read access by regular users, so the use of sudo will be required if you get a message like this: debsums: can't open at file /etc/at.deny (Permission denied).

If you run debsums with no options, it will check every file on the system that it knows about. The output can be redirected to a file if needed for later. The filename that debsums prints out will be accompanied by an OK status on the right side of the output if the MD5sum checks out for the file. Other messages may be printed out, such as md5sums missing for a certain file, or the word REPLACED if the MD5sum does not match.

You will need to be wary of false positives. If you want to use this tool as a baseline for assessments at a later date, you will want to get everything set up the way you want and re-generate MD5sums for stuff that is missing or incorrect. That way, you know you have the latest information.

This command will check every file on the system against the stock md5sum files. You can see there are some missing and replaced files. You would want to verify that the system does not already have problems with these files before you re-generate MD5sums for everything:

$ debsums

/usr/bin/acpi OK

/usr/share/man/man1/acpi.1.gz OK

/usr/share/doc/acpi/README OK

/usr/share/doc/acpi/AUTHORS OK

...

/usr/share/app-install/icons/pybliographic.png OK

debsums: no md5sums for bsdutils

debsums: no md5sums for bzip2

debsums: no md5sums for cdrecord

...

/usr/share/locale-langpack/en_AU/LC_MESSAGES/adduser.mo REPLACED

/usr/share/locale-langpack/en_AU/LC_MESSAGES/alsa-utils.mo OK

...

If you want to save this information to a file, you can redirect both stdout and stderr streams into a file. Adding a final ampersand puts the command in the background, so you can continue working at the shell:

$ debsums &> /tmp/foo &

To check the configuration files distributed with each package for changes, run debsums with the -a option:

$ debsums -a

/usr/bin/acpi OK

/usr/share/man/man1/acpi.1.gz OK

...

To check only configuration files, and ignore everything else, use the -e option. This is a good way to tell if you have inadvertently edited a config file you didn’t want to. You can see some of the X configuration files have been changed:

$ debsums -e

...

/etc/X11/Xresources/x11-common OK

/etc/X11/Xsession FAILED

/etc/X11/rgb.txt OK

/etc/init.d/x11-common OK

/etc/X11/Xsession.d/50x11-common_determine-startup OK

/etc/X11/Xsession.d/30x11-common_xresources OK

/etc/X11/Xsession.d/20x11-common_process-args OK

/etc/X11/Xsession.options FAILED

...

As debsums spits out a lot of information, you may want to see only changed files. Issuing debsums with the -c options will do that:

$ debsums -c

debsums: no md5sums for binutils

debsums: no md5sums for libaudio

...

With the preceding command, messages are printed for files that have no original md5sum info to check against. You can check for files that have no md5sum info by running debsums with the -l option:

$ debsums -l

binutilslibaudio2...

If you want debsums to show only errors, use the -s option to tell debsums to be silent except for errors:

$ debsums -s

debsums: no md5sums for binutils

debsums: no md5sums for libaudio2...

To check a specific package, give debsums a package name as an argument:

$ debsums coreutils

/bin/cat OK

/bin/chgrp OK

/bin/chmod OK

...

This will check only the files listed in that package’s md5sum file in the /var/lib/dpkg/info directory; so if the package does not come with an md5sum file, you will get an error:

$ debsums libaudio2

debsums: no md5sums for libaudio2

To generate the missing md5sums data for any package, use a combination of dpkg, the md5sum utility, and a little shell scripting. First, use dpkg -L to ask for a list of all the files dpkg knows about, in the package. The list dpkgreturns will have other lines of data in it besides just the filenames, so you pipe that output to grep and filter out everything that does not start with a slash.

On the second line, you have the shell test whether the line of output from dpkg is a directory or a file (directories start with a slash also). If it is a file, md5sum is run on the line of output, which at this point should just be a filename. Last, all output at the third line is saved into a text file with the same naming convention as the md5sum files in the /var/lib/dpkg/info directory.

This example shows how to create this script for the rsync package. However, you can choose to use any package that does not have MD5sums available.

$ for file in `dpkg -L rsync | grep ^/`; do

test -f "$file" && md5sum "$file";

done > /tmp/rsync.md5sums

What you gain from this command is an md5sum database you can burn to CD-ROM and use to check your system. If the MD5sums are on CD-ROM, they cannot be deleted accidentally, or be subject to filesystem problems of a hard disk. If you want to check your MD5sums at a later time, you can use the md5sum command with the -c option and feed it the filename of the md5sum data:

$ md5sum -c /tmp/rsync.md5sums

...

/usr/bin/rsync: OK

/usr/share/doc/rsync/examples/rsyncd.conf: OK

/usr/share/doc/rsync/README.gz: OK

/usr/share/doc/rsync/TODO.gz: OK

...

To use the rsync.md5sum file with debsums, you need to make one modification that will cause problems for md5sum, but is necessary for use with debsums: removing the leading slash in the filename. You can do this in a text editor, or with a little more shell scripting:

$ cat /tmp/rsync.md5sums

302916114c29191cd9c8cb51d67ee60a /usr/bin/rsync

...

To remove the leading slash in front of /usr/bin/rsync, you could use a text editor or just use the Stream Editor (sed):

$ sed -e 's# /# #g' /tmp/rsync.md5sums > /tmp/rsync.debsums

$ cat /tmp/rsync.debsums

302916114c29191cd9c8cb51d67ee60a usr/bin/rsync

With the leading slash removed, you can now copy rsync.debsums into the /var/lib/dpkg/info directory and debsums will be able to use it:

$ sudo mv /tmp/rsync.debsums /var/lib/dpkg/info/rsync.md5sums

$ debsums rsync

/usr/bin/rsync OK

/usr/share/doc/rsync/examples/rsyncd.conf OK

/usr/share/doc/rsync/README.gz OK

...

Building deb Packages

By rebuilding the .deb file that is used to build a Debian package, you can change it to better suit the way you use the software (for example, including an md5sum file). To begin, you need to extract a .deb file that you want to modify into a working directory. You then modify the file tree and control files to suit your needs.

For example, you could download and extract the rsync package and control files into the current directory by typing the following commands (your $RANDOM directory will be different of course):

$ aptitude download rsync

Then extract the package contents and the control files from the downloaded file. Note that the $RANDOM directory is found by typing /tmp/rsync_ and pressing Tab:

$ sudo dpkg -x rsync_3.0.9-1ubuntu1_amd64 /tmp/rsync_$RANDOM

$ sudo dpkg -e rsync_3.0.9-1ubuntu1_amd64.deb /tmp/rsync_17197/

Now change to your package directory, where you extracted the .deb file to, and have a look around. You should see a directory structure that looks very similar to this:

$ cd /tmp/rsync_17197

$ ls -lart

total 36

-rw-r--r-- 1 root root 37 Nov 8 2011 conffiles

-rw-r--r-- 1 root root 1012 Nov 8 2011 control

drwxr-xr-x 4 root root 4096 Nov 8 2011 etc

drwxr-xr-x 3 root root 4096 Nov 8 2011 lib

-rw-r--r-- 1 root root 1743 Nov 8 2011 md5sums

-rwxr-xr-x 1 root root 712 Nov 8 2011 postinst

-rwxr-xr-x 1 root root 113 Nov 8 2011 postrm

-rwxr-xr-x 1 root root 494 Nov 8 2011 prerm

drwxr-xr-x 4 root root 4096 Nov 8 2011 usr

Now you have to configure the package directory to fit the formats that dpkg will want for building the .deb file. This involves creating a subdirectory named rsync_3.0.9-1cn1.1/DEBIAN and moving the install files into it. The control file itself is a specially formatted file that contains header and content fields and is parsed by the package tools to print out information about the package:

$ sudo mkdir -p rsync_3.0.9-1cn1.1/DEBIAN

$ sudo mv control conffiles prerm postrm postinst rsync_3.0.9-1cn1.1/DEBIAN

You also need to move the etc/ and usr/ directories under the rsync_3.0.9-1cn1.1 directory:

$ sudo mv usr etc rsync_3.0.9-1cn1.1

You should end up with everything filed away correctly, and all that is left are the rsync_3.0.9-1cn1.1 directory, the lib directory, and the md5sums file in the current directory.

Now move the md5sums file you made earlier into your DEBIAN subdirectory and rename it md5sums. This will allow debsums to have some MD5sums to check:

$ sudo mv /var/lib/dpkg/info/rsync.md5sums rsync_3.0.9-1cn1.1/DEBIAN/md5sums

Now edit the control file to modify some of the information. You certainly don’t want to install your modified version of rsync with the same package info as the original. Open the control file in vi or another editor and change the Version line to reflect the one below. You will notice the word Version has a colon after it; this is the header field. The information field follows right after it. Be sure to maintain the space after the colon, and do not put any extra carriage returns or spaces in the file. It is very picky about formatting.

$ sudo vi rsync_3.0.9-1cn1.1/DEBIAN/control

...

Version: rsync_3.0.9-1cn1.1

...

A little farther down, you can add to the Description field. This will show up in the descriptions whenever someone views the package details. Notice the space right before the words fast remote. The space is part of the special formatting and is how dpkg tells the description text from the multiline header. Be sure to put a space in the first column if you wrap the description to the next line:

...

Description: Modified by CN 2013-02-01 to include md5sums.

fast remote file copy program (like rcp)

...

Now build your new package using dpkg -b and the name of the control file subdirectory you created. You will get a warning about Original-Maintainer being a user-defined field. You can safely ignore the warning.

$ sudo dpkg -b rsync_2.6.9-1cn1.1

warning, `rsync_2.6.9-1cn1.1/DEBIAN/control' contains user-defined field

`Original-Maintainer'

dpkg-deb: building package `rsync' in `rsync_3.0.9-1cn1.1.deb'.

dpkg-deb: ignoring 1 warnings about the control file(s)

You now have a new .deb file and can ask dpkg to display information about it. Just run dpkg with the -I option to see the new package info:

$ dpkg -I rsync_3.0.9-1cn1.1.deb

new debian package, version 2.0.

size 1004 bytes: control archive= 712 bytes.

970 bytes, 21 lines control

Package: rsync

Version: 3.0.9-1cn1.1

...

You could install the new rsync package at this point. This exercise is mainly a demonstration for building a custom package, not necessarily for hacking up the system needlessly. Nonetheless, the following code shows that this package will install and act like a regular Debian package. You want debsums to work also. Notice dpkg tells you about the downgrade:

$ sudo dpkg -i rsync_3.0.9-1cn1.1.deb

dpkg - warning: downgrading rsync from 3.0.9-1ubuntu1_amd64

to 3.0.9-1cn1.1.

(Reading database ... 88107 files and directories currently installed.)

Preparing to replace rsync 3.0.9-1ubuntu1_amd64

(using rsync_3.0.9-1cn1.1.deb) ...

Unpacking replacement rsync ...

Setting up rsync (3.0.9-1cn1.1) ...

The debsums utility now has some md5sum files to test with, and anywhere your new rsync package is installed, this will be the same:

$ debsums rsync

/usr/bin/rsync OK

/usr/share/doc/rsync/examples/rsyncd.conf OK

/usr/share/doc/rsync/README.gz OK

...

You can also ask dpkg to list your rsync package using the -l option to confirm that the new version is installed:

$ dpkg -l rsync

...

ii rsync 3.0.9-1cn1.1 Modified by CN 2013-02-01 to include md5sums.

Note You can find out more about building .deb files by visiting the Debian Binary Package Building HOWTO (http://tldp.org/HOWTO/Debian-Binary-Package-Building-HOWTO). The dpkg-deb man page is also a good source of info on deb package building.

Summary

Software for Ubuntu and other Debian-based distributions is packaged in the deb format. The Ubiquity installer is used to initially install Ubuntu. From the Boot menu, you can boot into a full Ubuntu environment and install from there, or run Ubuntu from a CD-ROM.

To install additional software, you can use the aptitude and APT utilities to get packages from online repositories. To install packages locally, as well as build custom Debian packages, you can use the dpkg utility. APT, aptitude, and dpkg all offer a means to query software. You can verify installed packages by using the debsums and md5sum utilities.