When using Linux on Debian, we often encounter some deb installation packages. We also know that it can be installed using the DPKG command.

Of course, also can download some software is compressed package, is not so convenient. Can we package it itself as a DEB installation package? Of course you can.

Creating a DEB installation package is a very simple matter.

1, understand deb installation package structure

Before making the installation package, let’s look at the contents of the DEB package:

This is what I’m going to pack, except for the DEBIAN folder, all of which are application files. The rest of the directories here mimic the installation directory (which looks like the same structure as the root directory after installation), because the deb package installs the content in the root directory /.

The DEBIAN folder must contain the Control file, which represents the basic information about the installation package.

In addition, there can be:

  • preinstScripts that are executed before software installation
  • postinstThe script is executed after the software is installed
  • prermScripts to be executed before software uninstallation
  • postrmScripts that will be executed after the software is uninstalled

These four scripts are not required; if they are, the four script files must have executable permissions.

2. Start making the installation package

Today we downloaded Typora, but in compressed file format, so let’s start by making the installation package of Typora.

(1) Create a directory to store all files

I created a folder called pack, in the/home/maiqu/Downloads/pack, placing the installation package content and configuration. The following is also used as an example.

(2) to createDEBIANFolder and writecontrolfile

We create a DEBIAN folder in the Pack folder, create a new Control file in it, and edit the Control file.

Here’S my control:

Package: Typora Version: 13.6.1 Section: utils Priority: Optional Architecture: AMd64 Installed-size: 218600 Maintainer: swSK33 <[email protected]> Provides: Typora Description: Provides the Typora installation package.Copy the code

The meanings of the above fields are as follows:

  • PackageThe package name
  • VersionThe version number
  • SectionCategory of software, which can beutils,net,mail,text,devel, etc.
  • PriorityThe degree of software’s importance to the system, e.grequired,standard,optional,extra, etc.
  • ArchitectureArchitecture, 32-bit software to filli386In 64-bit softwareamd64If it can run on both 32-bit and 64-bit systems, you can enter this parameterall
  • Installed-SizeSize after installation, unit: KB
  • MaintainerMaintainer, forMaintainer name < mailbox >In the form of
  • ProvidesThe supplier
  • Descriptiondescribe

The above fields are required or commonly used fields. In addition, the control file can have the following fields. The following fields are not required and are added as needed:

  • EssentialSpecifies whether it is the most basic package in the systemyesornoIf so, this indicates that the software is a stable and normal operation of the system software package, does not allow any form of uninstall
  • DependsOther software packages and libraries on which the software depends. If multiple software packages are required, separate them by commas (,)libc6, default-jre, indicating that the software package depends onlibc6anddefault-jreBoth packages are indispensable.)
  • Pre-DependsYou must install and configure dependent software packages and libraries before software installation
  • RecommendsThis field indicates the additional packages recommended for installation
  • SuggestsOther software packages are recommended for installation

Note that a blank line must be left at the end of the Control file, otherwise packaging will report an error.

(3) Put the contents to be packed in

The rest of the content is packaged software content and is released directly to the root directory. So we need to keep the directory structure here as well.

For example, if I want typora to be installed in /opt, let’s create the opt folder in pack and place typora in the opt folder:

We know that exceptDEBIANFolders and everything else will go directly to the root directory, so we will simulate the installation directory here and organize the application files so that they will be installed where we want them.

(4) Shortcuts

I wrote a blog on how to create shortcuts for Linux, so I won’t bother to write shortcuts for Linux. I will refer to this blog: links

Of course, we know that the shortcut files are located in /usr/share/applications, so here we need to create /usr/share/Applications in our pack folder and create a new desktop file to represent the shortcut.

Note, however, that the shortcut’s executable, icon, and run directory point must correspond to the location of our application after the installation package is completed, as shown below:

3, packaging

You have just finished writing the installation package configuration file and are now ready to package it. Package with DPKG command:

dpkg -b "Directory to pack" "Generate deb installation package directory"
Copy the code

I stay packaged content in/home/maiqu/Downloads/pack folder, so I execute the command:

cd /home/maiqu/Downloads
dpkg -b "pack" "Typora-linux.deb"
Copy the code

Wait until the installation package is built, then we can install it using DPKG -i!

To uninstall, just use apt remove and the Package name is the value of the Package field in the control file above.