How to Extract / Decompress .deb file in Ubuntu 20.04/22.04 [Graphical & Command Line]

Got a .deb file and want to extract or decompress it? Here’s how to do the trick in Ubuntu, Debian and other Linux in different ways.

DEB file:

The file with .deb extension is an installer package for Debian and Ubuntu based systems. Similar to EXE file for Windows, DEB is a commonly used method to install apps in Ubuntu/Debian Linux.

Sometimes user might need to extract a file from deb, or edit the scripts in a third-party deb that are built incorrectly. And, here’s how to extract / decompress the package in both graphical and command line ways.

Method 1: Extract DEB with System Archive Manager:

The system archive manager in most of today’s Linux desktops has the ability to extract .deb files.

Firstly, right-click on the file in file manager and click on “Open With Other Application” option. Next, select ‘Archive Manager‘ to open it in pop-up dialog.

When the deb opens in Archive Manager, you’ll mostly see the following 3 files:

  • debian-binary
  • data.tar.xz
  • control.tar.gz

While debian-binary stores the version of deb package format, data.tar.xz contains all the files to be installed on system. And, control.tar.gz includes the ‘control’ file with basic package information and list of dependency packages. As well, it may have ‘pre-install‘ and ‘post-install‘ scripts that run automatically during the installation process.

And, here you just need to choose the content you need, and click on ‘Extract’ button. Then browser and use them in file manager.

Method 2: Decompress & Re-pack DEB via dpkg-deb command:

dpkg-deb is the command line manipulation tool for .deb file. It’s a good choice to decompress and re-pack the package, as the previous method might NOT work sometimes.

Firstly, open a ‘terminal’ window (or connect to server console) from start menu. When it opens, run commands below as need:

NOTE: using dpkg-deb will mess up file permission and ownership on file extraction! If you want to re-pack them into DEB again, use ‘fakeroot’ to run the commands below as script or try Method 3.

  • Navigate to the folder that contains the deb file via cd command. For example, go to ‘Downloads’ folder by running command:
    cd ~/Downloads
  • List content in current working directory via:
    ls
  • And, decompress deb package into ‘tmp’ folder via command:
    dpkg-deb -R filename.deb tmp

    Create via mkdir tmp command if ‘tmp’ folder not exist. User may then go to tmp folder and do what ever as prefer to the files.

And, to repack them from tmp folder into a new DEB package, use command:

dpkg-deb -b tmp new_file.deb

Method 3: use ar command to do decompress and re-package process:

ar is a command line tool to create, modify, and extract from archives. User may use ar command to handle DEB file without worrying about permission and ownership. And, ar is available NOT only in Ubuntu/Debian Linux, but also CentOS, Rocky Linux, and other Linux.

Open terminal (or connect to command console) and go to the directory that contains the DEB package. Then do commands below to extract ‘control.tar.gz’ and repack it.

NOTE: A deb package may contain either ‘control.tar.gz‘ or ‘control.tar.xz‘, use the commands below accordingly.

  • Create and go to ‘tmp’ folder:
    mkdir -p tmp && cd tmp
  • Extract content of ‘control.tar.xz’ from DEB into the folder:
    ar p ../filename.deb control.tar.xz | tar -xJ

    DEB sometimes contain the control package via “control.tar.gz”, so the command will be:

    ar p ../filename.deb control.tar.gz | tar -xz
  • Now edit the control file, scripts under current directory. And finally re-pack it into “control.tar.xz” (or “control.tar.gz”):
    tar Jcf control.tar.xz *[!z]

    Here do use the original format! For ‘control.tar.gz’, use command:

    tar zcf control.tar.gz *[!z]
  • Finally, make a copy of original deb file:
    cp ../filename.deb ../new_file.deb

    And re-pack the edited version of control.tar.xz into new deb:

    ar r ../new_file.deb control.tar.xz

    Or re-pack the control.tar.gz via:

    ar r ../new_file.deb control.tar.gz

Summary:

For desktop PC, the system Archive Manager can extract a .deb package in most time. Besides, dpkg-deb command is available to decompress all files and re-pack them, though ‘fakeroot’ is required to avoid permission and ownership issue! As well, ar is a good choice to extract and repack control archive without worrying about permission and ownership issue.

Exit mobile version