# Debian building packages Debian packages (`.deb`) are the standard distribution format. Building custom packages requires source and metadata. ## Package components A source package consists of three files: - `.orig.tar.gz`: original upstream source - `.debian.tar.gz` or `.diff.gz`: Debian-specific patches and metadata - `.dsc`: metadata file (dependencies, checksums) Example: ``` hello_2.10-1.orig.tar.gz hello_2.10-1.debian.tar.gz hello_2.10-1.dsc ``` ## Extracting source Extract source package: ```bash dpkg-source -x hello_2.10-1.dsc cd hello_2.10-1 ``` This unpacks upstream source and applies Debian patches. ## Building Install build dependencies: ```bash cd hello_2.10-1 sudo apt build-dep . ``` Build package: ```bash debuild # builds, signs, creates .deb debuild -us -uc # builds, no GPG signing dpkg-buildpackage # lower-level alternative ``` Output: `.deb` file in parent directory. ## Installing custom package Install locally-built package: ```bash sudo dpkg -i hello_2.10-1_amd64.deb sudo apt install ./hello_2.10-1_amd64.deb # also resolves dependencies ``` ## Creating from scratch Create simple `debian/` directory structure: ``` source/ ├── debian/ │ ├── control # package metadata │ ├── rules # build instructions │ ├── changelog # version history │ └── copyright # license info └── main.c ``` Minimal `debian/control`: ``` Source: myapp Maintainer: Your Name Section: utils Priority: optional Build-Depends: debhelper-compat (= 13) Standards-Version: 4.6.0 Package: myapp Architecture: any Depends: ${shlibs:Depends} Description: My Application A brief description. ``` Minimal `debian/rules`: ```makefile #!/usr/bin/make -f %: dh $@ ``` Then build: ```bash debuild -us -uc ``` ## Contributing to Debian To formally contribute: 1. Check existing packages 2. Understand Debian Policy 3. Create quality package 4. Find sponsor (established developer) 5. Submit patch or new package 6. Go through review process See [Debian New Maintainers Guide](https://www.debian.org/doc/manuals/maint-guide/). ## Key files - `debian/control`: package metadata, dependencies - `debian/rules`: build rules (often just `dh $@`) - `debian/changelog`: version history (mandatory format) - `debian/copyright`: license and copyright info - `debian/install`: files to install - `debian/systemd/`: systemd units ## Tips - Always check copyright and licensing - Test package install/removal thoroughly - Use `debhelper` (`dh`) to simplify `debian/rules` - Never hardcode paths; use `/usr/bin`, not `/opt/bin` - Clean source tree: `debclean` or `debuild clean` - Linting: `lintian package.deb` checks for common issues Building quality packages requires testing and knowledge of Debian conventions.