Skip to content

Complete Guide to Building Software Packages on the Debian Platform ​

Schematic diagram of the postrm script cleanup logic and the purge trap

From maintainer scripts to hands-on packaging — a complete knowledge system for understanding Debian package building in one article.

Why is there this special topic? ​

When maintaining and delivering self-developed services, package the application into a standard .deb Packaging is the most standardized and easiest-to-maintain delivery method. However, Chinese-language materials on Debian packaging are either overly fragmented or remain at the "as long as it runs" level, lacking...Maintainer script lifecycle systematic explanation of.

This special topic was created precisely to solve this problem.

Special Topic Content Overview ​

This topic has a total of Six main articles+A reading guide, step by step build up a complete knowledge system of Debian packaging:

ChaptertitleCore content
IntroductionThis articleSpecial Topic Overview and Reading Guide
PrologueDebian Packaging PrimerThe troika of control, rules, and changelog
Chapter 1Complete interpretation of the postinst scriptPost-install script execution mechanism and best practices
Chapter TwoProper usage of the prerm scriptDetailed scenario-based explanation of pre-uninstall scripts
Chapter 3Cleanup logic of the postrm scriptThe boundaries and pitfalls of remove vs purge
Chapter 4Golang Project Packaging in PracticeMulti-stage Docker build + systemd integration
Chapter 5Hands-on Vue Project PackagingStatic resource deployment + Nginx automatic configuration

Who is this topic suitable for? ​

✅ Suitable for you if: ​

  • Need to package your own application (Go/Python/Node/VUE, etc.) as .deb Package delivery

  • Hope you understand.postinst,prerm,postrm lifecycle and trigger scenarios

  • Want to learn about production-grade packaging solutions, including systemd integration, configuration retention, data cleanup, etc.

  • We are setting up a CI/CD pipeline and need to standardize the build and delivery process.

⚠️ Not for you if: ​

  • Only want to use fpm or checkinstall Build a "usable package", without caring about lifecycle conventions.

  • No interest in Debian packaging at all (so how did you end up here? 😄)

Reading roadmap ​

Read from the prologue to chapter five in order to build a complete knowledge system.

Route 2: On-demand skimming (suitable for experienced developers) ​

Your needsRecommended Reading
I want to understand the lifecycle of maintainer scripts.Chapter 1 → Chapter 2 → Chapter 3
I want to package the Go project as a .deb.Prologue → Chapter 4
I want to package the VUE project as a .debPrologue → Chapter 5
encounter deconfigure SceneChapter 2 (focus on the deconfigure section)
Encounter purge Cleanup issuesChapter 3 (focus on the purge section)

The core concept of the topic ​

1. Understand the lifecycle, rather than memorizing scripts ​

postinst,prerm,postrm do not exist in isolation; together they constitute the software package's full lifecycle Understanding when each script is triggered is more important than memorizing script templates.

2. Configuration preservation is the highest priority. ​

Never overwrite user-modified configuration files during upgrades. This is the first principle of Debian packaging. All scripts in this topic follow this principle.

3. Reproducible build environment ​

Use Docker multi-stage builds to ensure that anyone can build exactly the same result on any machine..deb Bag.

Practical Project Overview ​

This topic includes two complete practical case studies:

Project Typetech stackpackaged artifactsDelivery format
Backend serviceGolang + systemdbinary file.deb bag
Frontend applicationVUE + NginxStatic resources + Nginx configuration.deb bag

Both cases include:

  • ✅ Complete Docker build file (builder.Dockerfile)

  • ✅ Automated build script (Makefile)

  • ✅ Production-grade maintainer script (postinst,prerm,postrm)

  • ✅ Deployment and Verification Guide

Usage recommendations ​

1. As a template reference ​

The scripts and configurations in this topic have all been verified in production environments and can serve as your project's Packaging template Copy and use directly. Just take appname/apiserver/cms-manager Simply replace it with your project name.

2. As learning material ​

If you are still unfamiliar with Debian packaging, it is recommended to start from the prologue and read in order. At the end of each chapter, there is also attached Practical Exercise and Pitfall Avoidance Guide, you can read and practice at the same time.

3. As a troubleshooting manual ​

If you encounter problems during actual packaging (for example postrm Failure causes the package to be unable to be reinstalled), you can jump directly to the corresponding section to view the problem analysis and solution.

Official documentation ​

Community tools ​

toolPurposeApplicable scenarios
dh-makeGenerate a Debian packaging templateGetting Started
debhelperAutomated build toolsetOfficial recommended solution
fpmA simple and fast packaging toolRapid build, non-standard
checkinstallGenerate .deb from source installationpersonal use

This topic adopts debhelper + dh + Docker Solution, balancing standardization and automatability.

Quick Start ​

If you want to Start immediately Package the Golang project as .deb, jump directly to:

👉Chapter 4: A Complete Guide to Packaging Golang Projects as Debian Packages

If you want to Start immediately Package the VUE project as .deb, jump directly to:

👉Chapter 5: Packaging a VUE Project as a Debian Package and Automatic Nginx Configuration

If you want to Learn from scratch, Please start from the prologue:

👉Prologue: Introduction to Debian Packaging — Detailed Explanation of debian/control, rules, and changelog

Keep updated ​

This series will be continuously revised based on updates to the Debian packaging toolchain and feedback from readers. If you have any suggestions, questions, or find a bug, you can contact me 🙌

Wish you a happy packing!🚀

最后更新2026/11/07 14:16
如果你觉得这篇文章有帮助,或者想聊聊技术、工作,欢迎通过下面方式联系我:
contact fishfinal