Table of Contents
deb package analysis
Create deb package
What can be improved in the above way of making deb packages:
Home Computer Tutorials Computer Knowledge It's so easy to make a deb package in Linux: Analysis of the internal composition and usage principles of Ubuntu's deb installation package file

It's so easy to make a deb package in Linux: Analysis of the internal composition and usage principles of Ubuntu's deb installation package file

Feb 19, 2024 pm 01:21 PM
linux document deb

Its so easy to make a deb package in Linux: Analysis of the internal composition and usage principles of Ubuntus deb installation package file

Deb file is an archive file used to distribute and install Linux Debian and its derivative distribution programs, usually containing application data. They come in handy for handling dependencies, desktop integration, and running pre- and post-installation scripts. Another package format similar to the Deb format is the rpm file commonly used in Fedora series distributions.

This article demonstrates how to make a simple deb package through examples, explains the role of each file in the deb package, and how to take effect and maintain it after installation.

deb package analysis

deb is a common Unix ar archive format that contains application and other utility files. The key component is the control file (control), which contains important information about the deb package and the installer.

  • Internally, the deb package contains a collection of files that simulate the typical file system directory structure of Linux, such as /usr, /usr/bin, /opt, etc. During installation, files placed in one of these directories are copied to the same location in the actual file system. For example, binary files such as /usr/bin/binaryfile in the package will be installed to the system's /usr/bin/binaryfile.
  • Externally, all deb package files follow a specific naming convention:
_-_.deb
Copy after login

Suppose you want to publish a program named mynano, version 1.0, which is built for 64-bit processors (AMD64). Your deb filename will be something like mynano_1.0-0_amd64.deb

Create deb package

We are ready to generate the package. Please make sure your system has the dpkg-deb tool (provided by the dpkg package) installed. The final deb package will be generated using dpkg-deb later.

(1) Create a working directory to store the package files and name them according to the previous naming convention.

mkdir mynano_1.0-1_amd64/
Copy after login

(2) Create the internal structure and place the program files where they should be installed on the target system. Let's say you want to install the executable to: /usr/bin/

First create the directory:

mkdir -p mynano_1.0-1_amd64/usr/bin/
Copy after login

The -p flag of the mkdir command will create nested directories. If any of the directories does not exist, it will be created automatically. Then copy the executable into it:

# 假设你开发的程序可执行文件为 ~/YourProjects/mynano/src/targets/release/mynano
cp ~/YourProjects/mynano/src/targets/release/mynanomynano_1.0-1_amd64/usr/bin/
Copy after login

(3) Create the file control. This file is located in the DEBIAN directory (note that the directory name is in capital letters)

Create the folder first: DEBIAN

mkdir mynano_1.0-1_amd64/DEBIAN
Copy after login

Then create an empty file: control

touch mynano_1.0-1_amd64/DEBIAN/control
Copy after login

Fill in the control file content:

Package: mynano
Version: 1.0
Architecture: amd64
Maintainer: linuxlibs 
Description: 基于nano的自定义编辑器
Depends: nano (>= 5.0)
Copy after login

in:

  • Package–Program name;
  • Version–Program version;
  • Architecture—Target architecture;
  • Maintainer– Name and email address of the person responsible for package maintenance;
  • Description – A brief description of the program.
  • Depends- Other packages this package depends on.

The file may contain other useful fields, such as Depends pointing out the deb package's dependency list. Then if you use the apt command to install the deb package, the nano>=5.0 version of the software package will be installed first, and then mynano will be installed.

(5) The last step: Build the deb package and call dpkg-deb as follows:

dpkg-deb --build --root-owner-group 
Copy after login
Copy after login

In our example:

dpkg-deb --build --root-owner-group 
Copy after login
Copy after login

The –root-owner-group flag here makes all deb package contents owned by the root user, which is the standard method. If there is no such flag, the owner of all files and folders is your current user, but considering that the system where the deb package will be installed does not necessarily have an account with the same name as yours, use –root-owner-group more reasonable.

The above command will generate a .deb file next to the working directory, or print errors if there are errors or missing in the package. If the operation is successful, you can distribute the generated deb package to others.

(6) Use deb package to install into the system: You can see that when installing the deb package we made through apt method, the dependency will be automatically installed: nano software package

# apt install ./mynano_1.0-1_amd64.deb
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成
注意,选中 'mynano' 而非 './mynano_1.0-1_amd64.deb'
将会同时安装下列软件:
nano
建议安装:
hunspell
下列【新】软件包将被安装:
mynano nano
升级了 0 个软件包,新安装了 2 个软件包,要卸载 0 个软件包,有 79 个软件包未被升级。
需要下载 280 kB/1,135 kB 的归档。
解压缩后会消耗 881 kB 的额外空间。
您希望继续执行吗? [Y/n] y
获取:1 /root/my-nano-editor-src/mynano_1.0-1_amd64.deb mynano amd64 1.0.0 [855 kB]
获取:2 https://mirrors.ustc.edu.cn/ubuntu jammy/main amd64 nano amd64 6.2-1 [280 kB]
已下载 280 kB,耗时 1秒 (422 kB/s)
正在选中未选择的软件包 nano。
(正在读取数据库 ... 系统当前共安装有 231799 个文件和目录。)
准备解压 .../archives/nano_6.2-1_amd64.deb...
正在解压 nano (6.2-1) ...
正在选中未选择的软件包 mynano。
准备解压 .../mynano_1.0-1_amd64.deb...
正在解压 mynano (1.0.0) ...
正在设置 nano (6.2-1) ...
update-alternatives: 使用 /bin/nano 来在自动模式中提供 /usr/bin/editor (editor)
update-alternatives: 使用 /bin/nano 来在自动模式中提供 /usr/bin/pico (pico)
正在设置 mynano (1.0.0) ...
正在处理用于 install-info (6.8-4build1) 的触发器 ...
正在处理用于 man-db (2.10.2-1) 的触发器 ...
Scanning processes...
Scanning processor microcode...
Scanning linux images...
Copy after login

(7) [Optional] Uninstall the installed software mynano:

# apt remove mynamo -y
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成
下列软件包将被【卸载】:
mynano
升级了 0 个软件包,新安装了 0 个软件包,要卸载 1 个软件包,有 79 个软件包未被升级。
解压缩后会消耗 0 B 的额外空间。
您希望继续执行吗? [Y/n] y
(正在读取数据库 ... 系统当前共安装有 231872 个文件和目录。)
正在卸载 mynano (1.0.0) ...
Copy after login

(8) [Optional] Check the dependencies of mynano_0.1-1_amd64.deb: dpkg -I ./mynano*deb

What can be improved in the above way of making deb packages:

The above is the detailed content of It's so easy to make a deb package in Linux: Analysis of the internal composition and usage principles of Ubuntu's deb installation package file. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

What is vscode What is vscode for? What is vscode What is vscode for? Apr 15, 2025 pm 06:45 PM

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages ​​and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

How to use VSCode How to use VSCode Apr 15, 2025 pm 11:21 PM

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages ​​and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

See all articles