Repack installed packages on Ubuntu

ubuntu_logo_81x81I often try out several utilities on my system and forget to backup the deb packages. I was thinking of writing a small tool to repackage installed deb files on Ubuntu so that I can get back the deb file anytime I want. I found dpkg-repack which does exactly the same thing i.e. rebuild or regenerate a deb package from files installed on the system by the original package. It can handle a single package or a list of all packages on your system. Straight to the operations:

dpkg-repack is not installed by default. Install it:

# apt-get install dpkg-repack

To repackage a single package:

# dpkg-repack package_name

To repackage multiple or all the installed packages:

  1. List all the package present in your system in a file:
    # dpkg --get-selections | cut -f 1 > files.txt

    At this point you can edit the file to remove some packages

  2. You have to have package names space separated. Open the file in vi. Press gg to go to the first line and issue the following:
    :%s/\n/ /g

    Note that there is a space between / /. This will convert all the newlines to spaces.

  3. Issue the following to save and exit vi:
    :wq
  4. Copy the content of the file. Run the following to repackage:
    # dpkg-repack paste_file_contents_here

Leave a Reply

Your email address will not be published. Required fields are marked *