Professional Resume Template for Software Developers
How to make debian package from scratch (linux)
1. How to make debian package
from scratch
10/2023
2. Example of a directories :
● my-package/ is the top-level directory for your package.
● DEBIAN/ is where you place control files and scripts.
● usr/ is where you place files that will be installed on the target system.
Structure of a debian package
3. Inside the DEBIAN/ directory, create a control file with package metadata.
For example:
Place the binary or files you want to package into the appropriate directories. In this example, we have an executable
named my-executable in usr/bin/.
You can customize the package further by adding pre-installation and post-installation scripts, defining dependencies, and more in the
DEBIAN/control file.
Help : https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-binarycontrolfiles
Structure of a debian package
6. - You must be on a debian/ubuntu Linux distribution of course
- You need to have several packages :
$ sudo apt install dpkg
(ubuntu 22.04 LTS)
Requirements
7. Generation of a debian package
Navigate to the parent directory containing the my-package folder and run the following dpkg-deb command to build the
package:
This will create a Debian package file named my-package.deb in the current directory.
Manual : https://man7.org/linux/man-pages/man1/dpkg-deb.1.html
Help :
● https://www.iodigital.com/nl/history/intracto/creating-debianubuntu-deb-packages
8. Installation of a debian package
You can now install the debian package using dpkg:
To execute on the server to update!
MANUAL : https://doc.ubuntu-fr.org/dpkg
10. # Create the nn6-package (root directory) and the DEBIAN directory (for the
metadata)
$ mkdir -p nn6-package/DEBIAN
# Create the content’s directory
$ mkdir -p nn6-package/opt/
→ “opt” have been selected but we can choose freely any path ; it will installed into
/opt in the final filesystem !
$ tree
└── nn6-package/ # main folder of the package
├── DEBIAN/ # will contains the package’s metadata
└── opt/ # will contains the content of the
package
11. # Go into the nn6-package directory
$ cd nn6-package/opt/
# pull your update at the root of the content’s directory
$ git clone git@gitlab.enensys.com:tm-testtree/monitor/streamprobe/streamprobe-
vmaf.git .
$ tree
└── nn6-package/
├── DEBIAN/
└── opt/
└── streamprobe-vmaf/
└── your_executable
12. # go into the nn6-package/DEBIAN directory
$ cd nn6-package/DEBIAN/
# Generate info about package’s metadata
cat <<- EOF > control
Package: vmaf
Version: 1.0
Section: base
Priority: optional
Architecture: all
Maintainer: Thierry GAYET <thierry.gayet@enensys.com>
Description: Source code of the vmaf appliance
Homepage: https://www.enensys.com
EOF
Help : https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-binarycontrolfiles
20. - You must be on a debian/ubuntu Linux distribution of course
- You need to have several packages :
$ sudo apt-get install dpkg-dev debhelper build-essential fakeroot
(ubuntu 22.04 LTS)
Requirements
21. Create the Package Directory Structure: You need to create a directory structure for your package. Here's a minimal example:
package_name/
├── debian/
│ ├── control
└── source_code/
Replace package_name with the name of your package and source_code with the directory containing your source code.
22. Create the Control File: Inside the debian directory, create a control file that contains metadata about your package. Here's a basic example:
Source: package_name
Section: misc
Priority: optional
Maintainer: Your Name <your.email@example.com>
Build-Depends: debhelper (>= 12)
Standards-Version: 4.5.0
Package: package_name
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: A brief description of your package.
Customize the fields according to your package's details.
23. Build the Package: Use the dpkg-buildpackage command to build the Debian package. Ensure you are in the parent directory of the
package_name directory:
$ dpkg-buildpackage -rfakeroot -b
This command will build the Debian package.
24. Install the Package: After building the package, you can install it using dpkg:
$ sudo dpkg -i ../package_name_1.0-1_all.deb
Replace package_name_1.0-1_all.deb with the actual name of the generated .deb package file.
25. Verify the Installation: To verify the installation, you can run:
$ dpkg -l | grep package_name
This should list the package as installed.
26. Clean Up: After you're done, you can remove the package:
$ sudo dpkg -r package_name
28. - You must be on a debian/ubuntu Linux distribution of course
- You need to have several packages :
$ sudo apt-get install dpkg-dev debhelper build-essential fakeroot dh-make
(ubuntu 22.04 LTS)
Requirements
29. dh_make is a tool that simplifies the process of creating Debian source packages from upstream source code. It sets up the basic packaging files
and directory structure for you. Here's how to use dh_make to generate a Debian package.
Create a Working Directory: Create a directory to work in, where you'll place the source code and package files. You can create a new
directory, e.g., mypackage :
$ mkdir mypackage
$ cd mypackage
Download or Place Source Code: Download the source code for the software you want to package or place it in the mypackage directory. The
source code should be in a subdirectory within mypackage.
30. Run dh_make: Run the dh_make tool in the mypackage directory, specifying the type of software you're packaging. For example:
$ dh_make -s -c gpl -f ../source_code.tar.gz
● -s: Use the single-binary option.
● -c gpl: Set the software's license (replace gpl with the appropriate license).
● -f ../source_code.tar.gz: Specify the path to the source code archive.
Follow the prompts, including answering questions about the software's maintainer, email, and any other information required.
Package Configuration: dh_make will generate packaging files and directories. You may need to make some adjustments, such as:
○ Modify the debian/control file to specify package dependencies, architecture, and other package details.
○ Place any additional scripts, patches, or configuration files in the debian directory.
○ Review and edit the debian/rules file if needed to customize the build process.
31. Build the Package: Use debuild to build the package. This tool will handle the compilation, packaging, and other necessary steps.
$ debuild -us -uc
○ -us: Do not sign the source package.
○ -uc: Do not sign the changes file.
This command will create a .deb package and a source package in the parent directory.
Install and Test: Install the generated Debian package using dpkg:
sudo dpkg -i ../package_name_1.0-1_all.deb
Replace package_name_1.0-1_all.deb with the actual name of the generated package file.
Clean Up: After testing, you can remove the package:
$ sudo dpkg -r package_name
Submit to Debian Repository (Optional): If your package meets Debian's quality standards and licensing requirements, you can consider
submitting it to the Debian repository.
This process simplifies the initial setup for creating Debian packages, but further customization may be required based on the specific software
you are packaging. Additionally, you should follow Debian packaging guidelines to ensure the quality and compatibility of your package.
50. The dpkg tools can be used for managing (install, extract content, … ) :
$ dpkg -c ./test_2.0.0_amd64.deb
drwxr-xr-x root/root 0 2015-06-27 19:00 ./
drwxr-xr-x root/root 0 2015-06-27 19:00 ./usr/
drwxr-xr-x root/root 0 2015-06-27 19:00 ./usr/bin/
-rwxr-xr-x root/root 44790352 2015-06-27 19:00 ./usr/bin/test
drwxr-xr-x root/root 0 2015-06-27 19:00 ./usr/share/
drwxr-xr-x root/root 0 2015-06-27 19:00 ./usr/share/doc/
drwxr-xr-x root/root 0 2015-06-27 19:00 ./usr/share/doc/test/
-rw-r--r-- root/root 148 2015-06-27 18:45 ./usr/share/doc/test/changelog.gz
-rw-r--r-- root/root 33 2015-06-27 18:44 ./usr/share/doc/test/copyright
A debian package is just an ar archive. To extract data from a deb package, use the command ar with the -x flag:
$ ar -x ./test_2.0.0_amd64.deb
$ ls
control.tar.gz data.tar.gz debian-binary test_2.0.0_amd64.deb
$ tar -xzf control.tar.gz
$ tar -xzf data.tar.gz
$ dpkg-deb -x ./path/to/test.deb ./path/to/destination
$ dpkg -x ./test_2.0.0_amd64.deb .
51. The alien tool can be use to change the format :
Man : https://manpages.ubuntu.com/manpages/trusty/man1/alien.1p.html
$ sudo add-apt-repository universe
$ sudo apt update
$ sudo apt install alien
To convert an RPM package to DEB:
sudo alien --d file.rpm
sudo alien --to-deb file.rpm
DEB to RPM:
sudo alien -r file.deb
sudo alien --to-rpm file.deb
DEB to TAR.GZ:
sudo alien -t file.deb
sudo alien --to-tgz file.deb