Converting your C program into a package!

This is a guide for packaging and making a .deb file in Ubuntu. Suppose you’ve written some application, say a scientific calculator. It will contain files like calci.c and calci.h and some other files which perform specific functions. Now, what we will be doing is package these source files and creating a .deb file out of it.

Note: .deb is a compressed file which contains your source files. This file is unpacked when you run apt-get install <package name>

Make sure that your code works perfectly and fix the bugs in it. Lastly, add a suitable license for the source code. Avoid making any changes in the code during the process of packaging.

Now, your code is ready to be packaged!

Simply follow these steps and enjoy the process of packaging!

  1. Go to your home folder. Edit the .bashrc file using any editor.
    $vim .bashrc

    Go to the end of the file and add these two lines –

    export DEBEMAIL="your_email-id"  
    export DEBFULLNAME="yourname"

    Note:Don’t keep trailing spaces anywhere.

  2. Run the command –
     $gpg --gen-key

    This generates a gpg key which is used for digital signatures. This step has to be performed only if you are packaging for the first time. Remember the passphrase which you enter. You will need it later.

  3. Create a folder with a proper name. The format must be like this : <package name>-<version name>
    e.g mycalci-1.01
    Note: We separate the package name and version by a hyphen(-). These conventions have to be strictly followed.
  4. Copy all the source files into this folder.
  5. Write a Makefile. In the makefile, first line must be –
     DESTDIR =

    Keep this empty.
    You also have to write the install target at the end of the makefile. This helps apt-get to copy your files in /bin folder .  Simply add this code at the end of makefile.

     $mkdir -p $(DESTDIR)/bin
     $cp mycalci $(DESTDIR)/bin

    Precaution: Do not write make clean.

  6. Now, go to the directory containing the main folder. Create a .tar.gz of the source code. Run these two commands –
     $tar -cvf mycalci_1.01.orig.tar mycalci-1.01/  (This gives a orig.tar file)
     $gzip mycalci_1.01.orig.tar     (This gives a orig.tar.gz file)

    Note: Before executing these two commands, the source code must not change.

  7. Now, go to the folder containing the source files.
     $cd mycalci-1.01/

    and run the command


    This creates a debian folder in the current directory. It provides files with readymade templates and simplifies our task of packaging.

  8. Go to the debian folder
     $cd debian/

    For basic packaging, we require only changelog, compat, copyright, control, rules and source files. Keep these and delete all the rest.

  9. a) Open compat file. Replace 8 by 7.
    b) Open changelog. Replace nnnn with any number. Write a suitable comment in the angular braces.
    c) Open copyright. Replace the defaults with your details. Copy the license as it is under the debian files above for the source files.
    Note: The license must be same as that given in the source code. If your source code is released under GPL3, your packaging has to be done under  GPL3 only.
    d) Open control. Again, make the neccessary changes. Change standard version from 3.9.2 to 3.9.3. Change the architecture from ‘any’ to ‘all’ if you wish to make your package architecture independent.
  10. Now go to the parent folder.
    $cd ../../

    Execute these commands –

    $dpkg-source -b mycalci-1.01/

    This gives you a .dsc file like mycalci_1.01-1.dsc

    $lintian mycalci_1.01-1.dsc

    This is used to check if there are any errors in the files in debian folder. Proceed only if no errors.

  11. Now, again go to the folder containing the code –
    $cd mycalci-1.01/

    and run the command –


    Done! This creates a .deb file in your parent folder. Just go one directory behind to see this file.

  12. Once you have your .deb file ready, you are ready to unpack it and install it in your local system. To do this, run the command,
    $dpkg -i yourpackagename.deb

    This will install the package and copy the binary file in /bin folder as mentioned in the install target of the Makefile. Now, you can run your package from anywhere, any directory, just like you do ls and pwd from any directory :)Now share your .deb file with your friends and have fun! 🙂

Cheers! 🙂

If you have any queries or stuck at any step, do ping me! 🙂

Special thanks to Abhijit Sir and Shravan Aras for their guidance.


9 thoughts on “Converting your C program into a package!

    • Using pbuilder will involve some additional task like creating a base.tgz as well. This tutorial was meant to just create a .deb file and have some fun. I’ll myself study the pbuilder method in greater depth and post a tutorial sooner or later 🙂

  1. A very nice tutorial indeed.. I could create my own package easily.. 🙂

    Only 1 change I had to do is :
    In Makefile :
    Instead of :-
    $mkdir -p $(DESTDIR)/bin
    $cp xfig $(DESTDIR)/bin

    I had to use it like :
    $(MKDIR) -p $(DESTDIR)/bin
    $(CP) $(DESTDIR)/bin

  2. Pingback: Playing with a ‘sl’ program « Inception.. (एक सुरूवात..)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s