§2023-08-16

Creating a Debian package involves a series of steps to package your software in a format that can be easily installed, managed, and removed on Debian-based systems. Here's a basic guide on how to create a Debian package:

  1. Set Up Your Development Environment:

Make sure you have a Debian-based system (e.g., Debian, Ubuntu) for packaging. You'll need some essential tools like dpkg-dev, debhelper, and fakeroot. Install them using:

sudo apt-get install dpkg-dev debhelper fakeroot
  1. Organize Your Files:

Place all your software's files in a directory. You'll want to organize them following the Debian packaging conventions. The main directory should contain subdirectories like DEBIAN, usr, etc, etc. Your software's binaries go in the usr/bin directory, configuration files in etc, and so on.

  1. Create the Control File:

In the DEBIAN directory, create a file named control which provides information about the package. Here's an example of a simple control file:

Package: my-package
Version: 1.0
Maintainer: Your Name <your@email.com>
Architecture: amd64
Description: A brief description of your package

4.Create the Package's Scripts (Optional):

If your software requires specific setup or configuration scripts, you can include them in the DEBIAN directory, naming them preinst (before installation), postinst (after installation), prerm (before removal), and postrm (after removal). Remember to make these scripts executable.

  1. Set Permissions:

Make sure that your package's files have the correct permissions. Use chmod and chown to set the permissions and ownership appropriately.

  1. Build the Package:

Navigate to the directory containing your package files and run the following command to build the Debian package:

fakeroot dpkg-deb --build package-directory

Replace package-directory with the name of the directory containing your package files.

  1. Install and Test the Package:

Once your package is built, you can install and test it on your local system using:

sudo dpkg -i package-name.deb
  1. Clean Up:

After testing, you can remove the package using sudo dpkg -r package-name.

  1. Reiterate and Improve:

Packaging is an iterative process. You might need to refine your package, adjust dependencies, improve scripts, and follow best practices.

  1. Submit to Debian Repositories (Optional):

If you want to distribute your package widely, you can consider submitting it to Debian repositories. This involves more complex procedures and quality checks.

Remember that creating and maintaining Debian packages can become quite complex, especially for larger and more sophisticated software. It's recommended to consult the Debian documentation and other packaging guides for more detailed information as you get deeper into the process.


User is there a debian depository for the prebuilf packaages that I could learn, for example how to make a tree package ChatGPT Yes, Debian has an extensive repository of prebuilt packages that you can explore to learn how packages are structured, what files they contain, and how they are organized. You can learn a lot by examining existing packages. Here's how you can do it:

Package Repository: Debian's package repository can be accessed online. You can use a web browser to navigate through the repository or use tools like apt to search for and install packages. The repository is organized hierarchically by release and architecture.

Repository URL: http://deb.debian.org/debian/

  1. Using apt to Explore:

You can use the apt command-line tool to explore packages and their contents. To see information about a package without installing it, you can use the apt show command:

apt show package-name
$ apt show which
N: Unable to locate package which
N: Unable to locate package which
E: No packages found
alexlai@orgpi5Jammy:~$ apt show tree
Package: tree
Version: 2.0.2-1
Priority: optional
Section: universe/utils
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Florian Ernst <florian@debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 108 kB
Depends: libc6 (>= 2.34)
Homepage: http://mama.indstate.edu/users/ice/tree/
Task: xubuntu-desktop, lubuntu-desktop, ubuntu-mate-core, ubuntu-mate-desktop, ubuntu-budgie-desktop, ubuntu-budgie-desktop-raspi
Download-Size: 47.2 kB
APT-Manual-Installed: yes
APT-Sources: http://repo.huaweicloud.com/ubuntu-ports jammy/universe arm64 Packages
Description: displays an indented directory tree, in color
  1. To download the package without installing it, use the apt download command:
apt download package-name
alexlai@orgpi5Jammy:~/build/debian-proj$ ls -l
total 0
drwxrwxr-x 2 alexlai alexlai 6 Aug 16 14:51 src
drwxrwxr-x 2 alexlai alexlai 6 Aug 16 14:50 tree

alexlai@orgpi5Jammy:~/build/debian-proj$ cd src
alexlai@orgpi5Jammy:~/build/debian-proj/src$ apt download tree

alexlai@orgpi5Jammy:~/build/debian-proj/src$ cd ../tree/

alexlai@orgpi5Jammy:~/build/debian-proj/tree$ dpkg-deb -x ../src/tree_2.0.2-1_arm64.deb ./
alexlai@orgpi5Jammy:~/build/debian-proj/tree$ ls
usr
alexlai@orgpi5Jammy:~/build/debian-proj/tree$ ls usr/
bin  share
alexlai@orgpi5Jammy:~/build/debian-proj/tree$ ls usr/bin/
tree
alexlai@orgpi5Jammy:~/build/debian-proj/tree$ ls -l usr/bin/
total 72
-rwxr-xr-x 1 alexlai alexlai 72960 Feb 17  2022 tree

alexlai@orgpi5Jammy:~/build/debian-proj/tree$ ./ usr/bin/tree
-bash: ./: Is a directory
alexlai@orgpi5Jammy:~/build/debian-proj/tree$ ./usr/bin/tree
.
└── usr
    ├── bin
    │   └── tree
    └── share
        ├── doc
        │   └── tree
        │       ├── changelog.Debian.gz
        │       ├── copyright
        │       ├── README.gz
        │       └── TODO
        └── man
            ├── fr
            │   └── man1
            │       └── tree.1.gz
            └── man1
                └── tree.1.gz

9 directories, 7 files