217

I went to the Ubuntu wiki but got confused,there were too many ways. Please tell me an easy guide to Debian packaging.

BuZZ-dEE
  • 14,533
akshatj
  • 13,386

7 Answers7

140

This is a good HOWTO for creating a basic .deb file. It is suitable for creating .deb files for personal use but not stringent enough if you want to the package to be included in Debian / Ubuntu - for that you should read the Debian New Maintainer's Guide and/or the Ubuntu Packaging Guide (which I believe you've already tried).

A good tool for checking your .deb file for compliance is lintian (installable from the repositories).

There were two sessions here in the Ask Ubuntu chatrooms.

The Basics of Packaging on Ubuntu (Packaging: Part 1)

Ubuntu Packaging for Launchpad PPAs (Packaging: Part 2)

BuZZ-dEE
  • 14,533
dv3500ea
  • 37,734
15

What parts are you having trouble with? Although complicated, the guide seemed quite clear when I was following it.

Quick Summary:

  • Extract source .tar.gz
  • Run dh_make
  • Edit debian files
  • Run debuild
BuZZ-dEE
  • 14,533
Nathan Osman
  • 32,495
14

You can even use dpkg-deb for creating simple packages.

Here's a nice tutorial from Ubuntuforums.

Searock
  • 761
13

Originally posted on StackOverFlow, this guide is for pre-compiled or interpreted software:

The right way of building a deb package is using dpkg-buildpackage but sometimes it is a little bit complicated. Instead you can use dpkg -b <folder> and it will create your Debian package.

These are the basics for creating a Debian package with dpkg -b <folder> with any binary or with any kind of script that runs automatically without needing manual compilation (Python, Bash, Pearl, Ruby):

  1. Create the files and folders in order to recreate the following structure:

    ProgramName-Version/
    ProgramName-Version/DEBIAN
    ProgramName-Version/DEBIAN/control
    ProgramName-Version/usr/
    ProgramName-Version/usr/bin/
    ProgramName-Version/usr/bin/your_script
    

    The scripts placed at /usr/bin/ are directly called from the terminal, note that I didn't add an extension to the script. Also you can notice that the structure of the deb package will be the structure of the program once it's installed. So if you follow this logic if your program has a single file, you can directly place it under ProgramName-Version/usr/bin/your_script, but if you have multiple files, you should place them under ProgramName-Version/usr/share/ProgramName/all your files and place only one file under /usr/bin/ that will call your scripts from /usr/share/ProgramName/

  2. Change all the folder permissions to root:

     chown root:root -R /path/to/ProgramName-Version  
    
  3. Change the script's permissions:

     chmod 0755 /path/to/the/script
    
  4. Finally, you can run: dpkg -b /path/to/the/ProgramName-Version and your deb package will be created! (You can also add the post/pre inst scripts and everything you want, it works like a normal Debian package)

Here is an example of the control file. You only need to copy/paste it in to an empty file called "control" and put it in the DEBIAN folder.

Package: ProgramName
Version: VERSION
Architecture: all
Maintainer: YOUR NAME <EMAIL>
Depends: python2.7, etc , etc,
Installed-Size: in_kb
Homepage: http://foo.com
Description: Here you can put a one line description.This is the short Description.
 Here you put the long description, indented by 1 space.
muru
  • 207,228
8

The very easiest way to package something is to use checkinstall.

e8johan
  • 205
3

No, the simplest and clearest packaging guide in this world is

Packaging Java Applications for Ubuntu and Other Debian's

Few days ago, for my first application, I created DEB package by following this tutorial. Very clear and my app packaged succesfully. Yes, at least it is simplest for me.

You can compare it with Debian Packaging Guide.

Eliah Kagan
  • 119,640
1

Based on the accepted answer, I have made a Python script that will create a helloworld_1.0-1.deb package following this tutorial. You can modify it for your package.

Copy the script and run it with Python 3: python3 create_debian_package.py

#!/usr/bin/env python3
"""
This script is going to create a debian package
"""
import os

print('This script is going to create a debian package')

EDIT THIS SECTION WITH YOUR PACKAGE INFORMATION

include_hello_world_script = True # Set to False to manually copy your files and remove helloworld program package_name = 'helloworld' major_version = 1 minor_version = 0 package_revision = 1 section = 'base' priority = '' architecture = 'i386' #Change to armhf for Raspberry Pi depends = '' #For example: libsomethingorrather (>= 1.2.13), anotherDependency (>= 1.2.6) maintainer = 'Your Name <you@email.com>' #The space before each line in the description is important package_description = """Hello World When you need some sunshine, just run this small program! """

NO EDITING NEEDED BEYOND THIS LINE

version_name = str(major_version) + '.' + str(minor_version) + '-' + str(package_revision) full_package_name = package_name + '_' + version_name path = os.getcwd() package_folder = os.path.join(path, full_package_name) os.makedirs(package_folder, exist_ok=True) os.makedirs(os.path.join(package_folder, 'DEBIAN'), exist_ok=True) with open(os.path.join(package_folder, 'DEBIAN', 'control'), 'w') as file: file.write("""Package: """ + package_name + """ Version: """ + version_name + """ Section: """ + section + """ Priority: """ + priority + """ Architecture: """ + architecture + """ Depends: """ + depends + """ Maintainer: """ + maintainer + """ Description: """ + package_description)

if include_hello_world_script: script_destination = os.path.join(package_folder, 'usr/local/bin') os.makedirs(script_destination, exist_ok=True) helloworld_filename = os.path.join(script_destination, 'helloworld') with open(helloworld_filename, 'w') as file: file.write("""#!/usr/bin/env python3 print('Hello World!')""") os.chmod(helloworld_filename, 0o755)

input("Put your files in the package structure and press Enter to continue...") os.system('dpkg-deb --build ' + full_package_name)

Katu
  • 3,663