Home Linux Tips & Tricks Recreate Debian Binary Packages That Are Already Installed On A System

Recreate Debian Binary Packages That Are Already Installed On A System

By sk
Published: Last Updated on 5K views

This brief guide introduces an useful utility called dpkg-repack, which is used to recreate Debian binary packages that are already installed on debian-based system.

What is dpkg-repack?

Picture this scenario. You've installed some packages on your Debian-based system. And you want to install the same packages on another system. But you lost the binary archives i.e. the deb files. Would you download them again from their official website or repository?

What if the particular version of a specific package is no longer available elsewhere? No worries! Since they are already installed on your system, you can easily recreate the .deb files. Say hello to dpkg-repack!

The dpkg-repack is a commandline Debian package archiving tool to recreate Debian binary packages that are already installed on your system.

To put it succinctly, dpkg-repack utility can able to create a .deb file out of a debian package that is already installed on your system.

The dpkg-repack utility can be helpful in many situations where you want to,

  • recreate .deb files from existing installed debian packages,
  • easily copy packages from one system to another,
  • save the current state of a package before upgrade it,
  • backup a specific version of a package for future use,
  • save specific packages which are no longer available for download.

Install dpkg-repack in Debian, Ubuntu and derivatives

The dpkg-repack is available in the default repositories of Debian, Ubuntu and its variants. To install dpkg-repack, simply run the following command:

$ sudo apt install dpkg-repack

Recreate Debian binary packages with dpkg-repack

1. For the purpose of this guide, let us use Microsoft Teams application which I installed a while ago on my Ubuntu desktop.

$ dpkg -l | grep teams

Sample output:

ii  teams                                         1.3.00.5153                                amd64        Microsoft Teams for Linux is your chat-centered workspace in Office 365.

I no longer have the teams.deb file. I deleted it right after installing the Microsoft Teams application. I can go to the official download page and download it again. But why should bother downloading it over and over? I can now simply recreate the teams.deb file using dpkg-repack.

2. To create teams.deb file from already installed teams package with dpkg-repack utility, run:

$ dpkg-repack teams

Sample output:

dpkg-deb: building package 'teams' in './teams_1.3.00.5153_amd64.deb'.
recreate Debian binary packages with dpkg-repack utility
Recreate Debian binary packages with dpkg-repack utility

As you see, the above command recreated the "teams_1.3.00.5153_amd64.deb'" file from the Teams package that is already installed on my Ubuntu desktop. The newly created deb file will be saved in the current working directory.

Similarly, you can convert any installed Debian packages back to .deb packages using dpkg-repack utility.

3. It is also possible to recreate multiple deb files with space-separated:

$ dpkg-repack <package1> <package2> <package3>

4. If you can't rebuild the deb file due to any permission issues, try from fakeroot environment like below:

$ fakeroot -u dpkg-repack teams

One interesting feature of dpkg-repack utility is if any changes have been made to the package while it was unpacked (i.e. files in /etc modified), the new package will inherit the changes.

Viewing the contents of deb file

Step 1: You can view the contents of that deb file using command:

$ dpkg --contents teams_1.3.00.5153_amd64.deb

Sample output:

drwxr-xr-x root/root         0 2020-05-26 15:15 ./
drwxr-xr-x root/root         0 2020-05-26 15:15 ./usr/
drwxr-xr-x root/root         0 2020-05-26 15:15 ./usr/bin/
-rwxr-xr-x root/root       286 2020-02-20 16:46 ./usr/bin/teams
drwxr-xr-x root/root         0 2020-05-26 15:15 ./usr/share/
.
.
.
drwxr-xr-x root/root         0 2020-05-26 15:15 ./usr/share/teams/swiftshader/
-rwxr-xr-x root/root    286264 2020-02-20 16:46 ./usr/share/teams/swiftshader/libEGL.so
-rwxr-xr-x root/root   2677296 2020-02-20 16:46 ./usr/share/teams/swiftshader/libGLESv2.so
-rwxr-xr-x root/root 114964776 2020-02-20 16:46 ./usr/share/teams/teams
-rw-r--r-- root/root   1040912 2020-02-20 16:46 ./usr/share/teams/v8_context_snapshot.bin
view contents of deb files in linux
View contents of deb files in linux

Step 2: The dpkg-repack comes in handy when installing the same set of packages on multiple systems, just transfer them using external hard drive or via LAN to other systems and install them using dpkg command:

$ sudo dpkg -i <package-name>

Step 3: Please note that you still need to download the dependencies. To install the dependencies, run:

$ sudo apt-get -f install

Alternatively, you can find the dependencies of the package as described in the following link:

And then recreate all of them using dpkg-repack as described above.

Step 4: This will also help when you want to roll-back a package to the previous working version. For instance, let us say you just upgraded Vim package to new available version. If the new version is not working as expected, you can simply roll-back to the old version which you created earlier using dpkg-repack.

For more details, refer man pages:

$ man dpkg-repack

Resource:

You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More