dpkg tutorial – Package Manager for Ubuntu / Debian

dpkg or the debian package manager is package manager for debian and other debian based Linux distributions like Ubuntu. dpkg can be used for a variety of purposes

  1. Installation of packages
  2. Removal of packages
  3. Knowing the current state of a package
  4. Cloning a machine

Let’s see how each of these can be done using dpkg.

  1. Package Installation
    1. How to find the installed packages in your Ubuntu machine?
    2. How to see the list of available packages in Ubuntu?
  2. Package Removal
    1. dpkg: purge versus remove
    2. Remove all packages marked as rc by dpkg
    3. Purge packages using dpkg
    4. Remove a package marked as rc by dpkg
    5. Remove packages using dpkg
  3. Package listing (dpkg –list)
    1. What does pn correspond to in dpkg (–list)?
    2. What does ii correspond to in dpkg (–list)?
    3. What does rc correspond to in dpkg (–list)?
  4. Package Current State
    1. How to see the Current State of package (Ubuntu)?
    2. How to interpret the status of dpkg (–list)?
  5. Cloning a machine
    1. dpkg –set-selections: Clone your Ubuntu Machine (package state)
    2. dpkg –get-selections: Get the Current State of Your Ubuntu/Debian machine

Please leave your valuable comments.

Advertisements

dpkg –set-selections: Clone your Ubuntu Machine (package state)

If you want to clone another machine in a similar way as one of your other machine, you can make use of dpkg command.

What does cloning mean?

Cloning a machine means installing the same packages (sometimes even settings) as found in the source machine. dpkg allows you to get the current state of your machine – the set of packages installed in the machine and their state (whether installed or uninstalled)

Suppose you have the list packages_list containing the state of the source machine.

Now go to the destination machine and run the following command

$ sudo dpkg --set-selections < ./packages_list

This command will not install any packages, but only mark a state corresponding to every package.

For the actual installation, run the following command

$ sudo apt-get -u dselect-upgrade

This will install all the necessary packages. Some packages may be removed. In the end, both the source and destination machines will have the same state

dpkg –get-selections: Get the Current State of Your Ubuntu/Debian machine

dpkg can be used for a variety of purposes. It can be used to install and remove packages. But one of the best feature which you can use is to save the current state of your machine.

What is current state of your machine?
You may be wondering what does the current state means. Your ubuntu/debian machine is a collection of many packages. Every time your machine crashes, apart from losing the valuable data, you may also lose the information about various packages you installed in your machine.

dpkg –get-selections gives the list of all package names and their current state like installed, deinstalled etc.

$ dpkg --get-selections 

acpi-support                                    install
acpid                                           install
adduser                                         install
adium-theme-ubuntu                              install
aisleriot                                       install
akonadi-server                                  install
....

You can save the settings into a file using tee.

$ dpkg --get-selections | tee packages_list

acpi-support                                    install
acpid                                           install
adduser                                         install
adium-theme-ubuntu                              install
aisleriot                                       install
akonadi-server                                  install
....

You can make use of the file packages_list in many ways. Save it in your mail, so that you can use it later or even use it to clone another machine in a similar way.