Linux+: Applications 12 – Package Installation with dpkg

J

Jarret W. Buse

Guest
Linux+: Applications 12 – Package Installation with dpkg

Most users tend to install a lot of packages, or programs, to their Linux system. Understanding how to use the “dpkg” application, or at least how it works, can be important. Most users will tend to use apt-get or a Graphical User Interface (GUI) like Synaptic to perform the major functions dealing with packages.

The major functions of the “dpkg” command are as follows:

· Install
· Remove
· Upgrade
· Verify
· Query

This article deals with the “dpkg” subcommands which deal with installing packages. The subcommands for package installation are:

  • -i (--install) – install specified package
  • --unpack – uncompress a package
  • --configure – configure the unconfigured packages
  • --triggers-only – process all packages whose triggers have not been processed
  • --add-architecture – specifies architectures for which packages can be downloaded
  • --remove-architecture – removes the specified architecture from the list which is used to download and install packages for the acceptable architectures
  • --force-architecture – forces a package to be installed even if the architecture is incorrect to the local system

NOTE: The separation of the subcommands, or Actions, is not precise. My goal was to make the “dpkg” articles similar to the RPM articles.

To use the above actions with “dpkg”, you need to understand the process of what “dpkg” does. I went over the process in “Linux+: Applications 11 – dpkg Overview”, but that was a simple overview. To understand the process is important so you know what is going on in the background.

The steps are as follows, with more detail:

1. Package file is downloaded to the local system (this is the same as downloading any file to your local system from the Internet)
2. The control files are extracted from the .deb file. To see the control files in a package, use the command “ar –x package_name.deb” (the control files include the scripts such as “prerm”, “preinst”, etc.)
3. The version number of the package is retrieved from the control file and checked against the local database. If another version exists, the “prerm” script is run from the original package which stops any daemons used by the older package
4. Execute the “preinst” script in the newer package to be installed. The script checks for and stops any existing services which will be updated by the install
5. The new package is extracted while the old package files are backed up. If the install goes wrong, the old files can be restored
6. If this is not a new install, but another package exists with a different version, execute the “postrm” script of the older package. The script modifies links and associations for the new package. Files may also be removed which were created by the new package
7. The new package is configured as follows:
a. Unpack the conffiles from the new package and at the same time back up the old conffiles. If the install goes wrong, the old files can be restored​

b. Run the “postinst” script of the new package. The “postinst” script is used to finish any configuration items such as querying the user for needed information​

The syntax for “dpkg” is:

dpkg <actions> <options> <package_name>

For the examples, I will use the Debian package for the AVG anti-virus program which is called “avg2013flx-r3118-a6926.i386.deb”.

The subcommands, or actions, are as follows:

· -i – sudo dpkg –i avg2013flx-r3118-a6926.i386.deb

NOTE: The install requires Superuser permissions, so “sudo” is required. Be aware that the “dpkg” command does not download the necessary files. The “dpkg” command does not support dependencies, so any “deb” file with dependencies will not easily work with “dpkg”. The anti-virus package contains its dependencies.

· --unpack – sudo dpkg --unpack avg2013flx

NOTE: The name is not the package file name, but the package name. For any entry you see as “avg2013flx” requires the package name and not the file name.

· --configure – sudo dpkg --configure avg2013flx

· --triggers-only – sudo dpkg --triggers-only avg2013flx

· --add-architecture – sudo dpkg --add-architecture i386

NOTE: The various architectures are i386, amd64, etc.

· --remove-architecture – sudo dpkg --remove-architecture i386

· --force-architecture – sudo dpkg –force-architecture –i avg2013flx-r3118-a6926.i386.deb

These subcommands for “dpkg” can be important, but as you will read in the articles about “apt-get”, these subcommands are the basis of “apt-get”. The “apt-get” command can download the files and dependencies, unlike “dpkg”.

Make sure for the Linux+ Certification Exams you are aware of these commands and its actions.
 

Attachments




Members online


Latest posts


Top