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!
- Go to your home folder. Edit the .bashrc file using any editor.
$pwd /home/pratik $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.
- Run the command –
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.
- Create a folder with a proper name. The format must be like this : <package name>-<version name>
Note: We separate the package name and version by a hyphen(-). These conventions have to be strictly followed.
- Copy all the source files into this folder.
- Write a Makefile. In the makefile, first line must be –
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.
install: $mkdir -p $(DESTDIR)/bin $cp mycalci $(DESTDIR)/bin
Precaution: Do not write make clean.
- 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.
- Now, go to the folder containing the source files.
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.
- Go to the debian folder
For basic packaging, we require only
changelog, compat, copyright, control, rulesand
sourcefiles. Keep these and delete all the rest.
- a) Open
compatfile. Replace 8 by 7.
changelog. Replace nnnn with any number. Write a suitable comment in the angular braces.
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.
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.
- Now go to the parent folder.
Execute these commands –
$dpkg-source -b mycalci-1.01/
This gives you a .dsc file like 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.
- Now, again go to the folder containing the code –
and run the command –
Done! This creates a .deb file in your parent folder. Just go one directory behind to see this file.
- 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! 🙂
If you have any queries or stuck at any step, do ping me! 🙂