search
HomeComputer TutorialsComputer KnowledgeIt'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

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

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/

(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/

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/

(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

Then create an empty file: control

touch mynano_1.0-1_amd64/DEBIAN/control

Fill in the control file content:

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

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 

In our example:

dpkg-deb --build --root-owner-group 

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...

(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) ...

(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
This article is reproduced at:每日运维. If there is any infringement, please contact admin@php.cn delete
How to Use Roblox Quick Login on PC/Phone? Here Is a Full Guide! - MiniToolHow to Use Roblox Quick Login on PC/Phone? Here Is a Full Guide! - MiniToolApr 28, 2025 am 12:50 AM

If you want to log in to your Roblox account on a new device without inputting the password, Roblox Quick Login can help you do that. This post from php.cn tells you how to use the Roblox quick login feature with full steps.

PS5 vs Xbox Series vs PC: Which One Is Best for Hogwarts Legacy - MiniToolPS5 vs Xbox Series vs PC: Which One Is Best for Hogwarts Legacy - MiniToolApr 28, 2025 am 12:49 AM

Hogwarts Legacy is out now on PS5, Xbox Series X/S, and PC. Which is best for Hogwarts Legacy? If you’re confused, don’t worry. In this post, php.cn provides a tutorial about Hogwarts Legacy PC vs PS5 vs Xbox Series X/S, and you can have a look.

Download Realtek USB GbE Family Controller Drivers Windows 10/11 - MiniToolDownload Realtek USB GbE Family Controller Drivers Windows 10/11 - MiniToolApr 28, 2025 am 12:48 AM

In this post, php.cn Software will show you some information about Realtek USB GbE Family Controller, including its definition, usage, and how to download the Realtek USB GbE Family Controller driver on your Windows 10/11 computer.

Crucial T700 SSD Overview: It Has Record-Break Performance - MiniToolCrucial T700 SSD Overview: It Has Record-Break Performance - MiniToolApr 28, 2025 am 12:47 AM

Crucial T700 PCIe Gen5 NVMe SSD has been released for a period. You can follow this post to learn the related information about this SSD that has record-break performance. In this post, we also introduce some php.cn software to help you manage the SS

How to Download, Install, and Update RTX 4090 Drivers Win 10/11? - MiniToolHow to Download, Install, and Update RTX 4090 Drivers Win 10/11? - MiniToolApr 28, 2025 am 12:46 AM

If you have a GeForce RTX 4090 Ti in hand, it is important to download and install the corresponding driver in time to make it work properly. If you are confused about how to do that, follow this guide on php.cn Website to get a detailed tutorial.

Notion Dark Mode: How to Turn on and off on Desktop & Mobile - MiniToolNotion Dark Mode: How to Turn on and off on Desktop & Mobile - MiniToolApr 28, 2025 am 12:45 AM

Most people think that it is more harmful to look at a screen in the dark. The sharp light easily makes your eyes damaged. Therefore, many people will pursue a dark mode to lower the damage. But is it really useful? Is the dark mode available on Noti

How to Fix Valheim Stuck on Loading Screen? - MiniToolHow to Fix Valheim Stuck on Loading Screen? - MiniToolApr 28, 2025 am 12:44 AM

If you are complaining of Valheim stuck on loading screen and don’t know what to do. This guide on php.cn Website will help you to find suitable solutions. Try the solutions mentioned below one by one until your issue is gone.

Power Tactics to Disable and Clear Run History on WindowsPower Tactics to Disable and Clear Run History on WindowsApr 28, 2025 am 12:43 AM

If you frequently use the Run window to directly open tools or documents, you will find the matching list gradually becomes longer and longer. Some people are searching for methods to clear Run history to make it look clean. This php.cn post might gi

See all articles

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

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor