How to create / manipulate a .deb file of a compiled application

Debian package

First of all, as I mentioned in the title, this post is about how to create or manipulate deb files of an already compiled application. In this topic I’m not going to explain you how to create a deb starting from source code :)

I’ll try to give you every possible indication in this article, if you miss some information but find the article interesting, please comment and ask me how to make things I failed to explain.

Not going to tell you what a .deb file is and what it is for, but you should really know that a deb is just a common archive in an .ar format, camouflaged with another name. So, right clicking on the deb file and choosing to open it with a common compressed files manager (such as file roller in gnome and OpenGEU) will work and show you the contents of the file. Now, you can modify an already existent deb file or create one from scratch. Should you prefer the second option, don’t be scared, it really is a simple task.

A deb file contains two main files, so, to manipulate an existing deb, open it with an archive manager and extract those files wherever you wish. The files we are talking about are:

  • control.tar.gz
  • data.tar.gz

Now, create a new dir with the name of the applications you’re creating (in reality, the name of this dir means nothing but you may still want the name to have a meaning, just for your convenience..), then, inside of this dir, create a subdir called debian. Now, enter the debian dir and create another sub-dir called DEBIAN. All of this work is case sensitive so use the right letters. The dir structure at this point should look like this:

application_name –> debian –> DEBIAN

Very well now, you can open the file called control.tar.gz

Inside of this file you’ll find some other files, just extract them into the DEBIAN dir as they are. Now open the file called data.tar.gz and extract its contents into the debian dir as they are, with any contained folder and subfolder: in other words, leave the directory structure of the compressed archive unaltered.

Perfect, not we have just recreated the directory structure of the original deb file. Enter the DEBIAN dir, you’ll find there a file called “control” (without quotes, never consider quotes from now on in the article please).

control

This is the main “brain” of a debian file: it contains all of the informations reguarding this package, without this file the entire creation of a deb package has no meaning at all. A control file looks like this (quoting the contents of the opengeu-artwork-usplash’s control file as an example):

Package: opengeu-artwork-usplash
Version: 3.01
Section: x11
Priority: optional
Architecture: all
Depends: libc6 (>= 2.5-0ubuntu1), initramfs-tools (>= 0.40ubuntu30), usplash (>= 0.4-21)
Installed-Size: 1010
Maintainer: darkmaster <luca.darkmaster@gmail.com>
Conflicts: geubuntu-artwork-usplash
Replaces: geubuntu-artwork-usplash
Description: OpenGEU usplash image
The startup screen shown on OpenGEU boot, by default it is the Sunshine version, you can later change it to the Moonlight edition too using usplash-switcher.

Let’s analyze the important parts this file together:

  • Package: you have to put here the name of the package, never use spaces, never use a version number. It is case sensitive, be warned!
  • Version: of course, the version number / code. It can also be, for example, opengeu-3.0.2 or any other weird code, as long as the last part is a number. Always remember that chaning the version to a higher number triggers the system to consider that new file as an update of course!
  • Priority: optional, high, low, only system or security updated should have something like high in the priority.
  • Architecture: i386, amd64, all, you should specify here what platform this package is compiled for. If it is only an artowork or a metapackage, you can put all in the Architecture field.
  • Depends: a list of all the packages this package depends on. A metapackage, for example, can include almost nothing but depend on a lot of other packages so that installing this metapackage automatically installs a lot of other packages! That’s what happens with opengeu-desktop for example!
  • Conflicts: if you know that your package can’t work if another package is installed, well, you should then list that package here.
  • Replaces: Here you specify that this file replaces another package, maybe an old one. Useful if you change the name of the package into something else and whant the new package to be installed INSTEAD of the package to be replaced.
  • Description: put only a very short description in the first line, then enter a longer description on the second line, like it is shown in the example above.

Well, and that’s almost eveything about the control file. But this is not the only file you can find in the DEBIAN dir. For example, you could find also a prerm or postinst file, or you could find both of them: they are scripts.

postinst

This script will execute any action contained in it right after the installation of the package. Here’s an example, the contents of the postinst file contained in the opengeu-artwork-usplash package:

#!/bin/sh

set -e

case “$1″ in
configure)
update-alternatives –remove usplash-artwork.so /usr/lib/usplash/usplash-theme-opengeu-sunshine.so
update-alternatives –install /usr/lib/usplash/usplash-artwork.so usplash-artwork.so /usr/lib/usplash/usplash-theme-opengeu-sunshine.so 55
update-alternatives –install /usr/lib/usplash/usplash-artwork.so usplash-artwork.so /usr/lib/usplash/usplash-theme-opengeu-moonlight.so 55
update-alternatives –set usplash-artwork.so /usr/lib/usplash/usplash-theme-opengeu-sunshine.so
update-initramfs -u
;;
esac

So, right after the installation o the package, those commands are executed, very simply!

prerm

This script instead is executed right before the package is removed! Here are teh contents of the prerm file contained in the opengeu-artwork-usplash package:

#! /bin/sh

set -e

case “$1″ in
remove)
update-alternatives –remove usplash-artwork.so /usr/lib/usplash/usplash-theme-opengeu-sunshine.so
update-initramfs -u
;;
esac

If you are creating a new deb file from scratch, remember to right click on those files, move the permission tag and make them executable, or they won’t work.

Keeping the folders clean

Every time you create or modify a new text / script file, some temporary files are created and we don’t want them to go into the deb. So enable your file browser to see hidden files and remove the temporary files before compiling the deb!

Data

Every file that has to be installed into the system goes into the debian folder. Let’s say that this is like the heart of our deb package. Consider this folder as the “/” mount point of your system, the main system folder or whatever you call it. Basically, you have to recreate into the debian folder the structure of the folders and files you wish to be installed into the system. So, let’s say that our package has to install the usplash-theme-opengeu-moonlight.so file into the /usr/lib/usplash/ folder, then, you’ll have to create or edit the files and folders status to look like this:

package-name/debian/usr/lib/usplash/usplash-theme-opengeu-moonlight.so

Installing the deb file will cause the usplash-theme-opengeu-moonlight.soto be copied in the right place :)

You can of course add multiple files into the same package with multiple folder structures but remember that if you create a package containing the same files as another already installed package, and if this new package is not an upgrade to the other one, the installation will fail. apt-get will give you an error saying that the file is already contained in another package and therefore it cannot be overwritten.

Creating the real package

Now that we created the contents and the controls of the package, let’s build it so that a deb file is created for us automatically. Move yourself in the main folder of the application, in our example, it should be the “package-name” folder. Open a terminal here and run:

dpkg-deb –build debian

You’ll be asked to install some extra packages the first time you use this command, just do it and then run the command again. A debian.deb file will be created in the dir you are in, just rename it to mirror your tastes, I suggest you to try and name it with the same name you mentioned in the control file, followed by the file version, for example: opengeu-artwork-usplash-3.0.deb and remember never to use spaces!

Conclusions

The file is now ready to be installed. In this way and knowing the files structure you can create any new deb from scratch or edit an existent one, no difference. Just use any control file as a template. Remember to keep your folder structure clean and that it is case sensitive and you’ll soon create nice deb packages :D

About these ads

~ by thedarkmaster on May 24, 2008.

64 Responses to “How to create / manipulate a .deb file of a compiled application”

  1. Hi! Just a little notice. The command to build the package is wrong; the correct one is:

    dpkg-deb –build debian

    Ciao, beo! ;-)

  2. EEEh?? They look the same to me! What’s wrong? I just copy pasted a working command from the command line…

  3. ok now I get it, you used a single “-” i used two. Well, on my system it works with 2 –!

    • Here on Ubuntu 10.04 I also need two –.
      It’s more common to user double dash with long commands.

      The help says:
      dpkg-deb -b debian OR dpkg-deb –build debian

  4. bella guida, chiara e precisa.
    quasi quasi ti recensisco positivamente ;-)

    però non esponi in maniera sexy come Videomarta da Torino…

  5. Grazie grazie grazie, perchè non mi recensisci allora ;P
    E chi è videomarta da Toriiiiiino? Voglia di sbattermi in google zeeeeeeeroooooo….

  6. una ragazza diventata famosissima per i video che mette su youtube incui spiega l’informatica in pigiama (letteralmente).
    è attraente come Niels Bohr, simpatica come Alan Greenspan e intelligente come Jenna Jameson :-D .
    oramai vanta anche numerose imitazioni piuttosto divertenti e non troppo dissimili dall’originale…

  7. And how to create a .deb package? I look for how to create a meta package.

  8. Uhm… NTB, isn’t this entire post about that topic? Didn’t I explain it all?

  9. dpkg-deb –-build debian, isn’t right there? :P
    Anyway, Mr. AmrinZ, izzat u? :D

  10. hombre, a quando un post nuovo?
    magari mi faccio un account msn così ci si vede su pidgin per parlare di linux e amenità varie del bel mondo… ;-)

  11. CIao purtroppo con lo studio adesso non ho manco il tempo d scrivere un post…
    Questa estate ho così tante cose che vorrei fare… ma ci conosciamo? Sei D?

  12. e certo che sono io, schwartzkneipe

  13. yea yeah….

  14. Anyone get an error:
    >dpkg-deb: need an action option
    when they try to build a package?

  15. yes nick i get the same error

  16. […] http://thedarkmaster.wordpress.com/2008/05/24/how-to-create-manipulate-a-deb-file-of-a-compiled-appl… […]

  17. […] are some more useful notes on the structure of .deb files and how to create them. If you are interested in trying out the […]

  18. Hey.. thanks dude… explained clearly.

    dpkg-deb -b debian also works…

    cheers to author… :)

  19. How, and where, do you create a .changes file? I require that in order to upload any package to Mint’s repos.

  20. nice guide. is it possible to add ten deb package to make one deb package???

    • I don’t quite get the question, but I assume you would like to have a deb package able of installing 10 deb packages? In this case you just need to create a metapackage as described in the guide. Just put all the names of the packages you need in the control file, under dependencies.

  21. i got an error like this:

    dpkg-deb –b debian
    dpkg-deb: need an action option

    Type dpkg-deb –help for help about manipulating *.deb files;
    Type dpkg –help for help about installing and deinstalling packages.
    sundar@sundar-laptop:~$ dpkg-deb –build debian
    dpkg-deb: need an action option

    Type dpkg-deb –help for help about manipulating *.deb files;
    Type dpkg –help for help about installing and deinstalling packages.

  22. where did you run the command from?
    I mean, you read the guide right? So, you need to create a debian dir and inside it another DEBIAN dir with control files.
    Then you have to launch the command from inside the debian dir.

  23. Here are the steps i followed. correct me if i am wrong. did all work in my home folder. new dir name is mypackage.

    Step I:
    created folders…

    mypackage –> debian –> DEBIAN

    Step II

    Extracted one of the old debian package. i found data.tar.gz, control.tar.gz and debian-binary (text file)

    Step III

    found “control” folder after extracting control.tar.gz. so copied and pasted inside DEBIAN folder

    Step IV

    found “usr” folder after extracting data.tar.gz. so copied and pasted inside debian folder (now i have usr & debian folders inside “mypackage”)

    Step V

    in the terminal i gave following commands

    cd \mypackage
    cd \debian

    so now i am inside debian dir. finally to create .deb package i gave

    dpkg-deb –b debian

    here is the o/p of the above command

    dpkg-deb: need an action option

    Type dpkg-deb –help for help about manipulating *.deb files;
    Type dpkg –help for help about installing and deinstalling packages.

    I found the same o/p even if i dont use

    cd \mypackage
    cd \ debian

    Note: i also copied only control files (not folder) inside DEBIAN folder and gave dpkg-deb –b debian but it didnt work.

  24. This sign “\” is only used in windows, not linux. In linux you have to use this sign /. And in any case it is unneeded.
    I think you created all the folders correctly. Just to be sure, here’s the correct dir tree.

    mypackage – contains only the debian dir
    debian – contains all the files to be installed and the DEBIAN dir
    DEBIAN – contains the control file and eventually scripts.

    Now, to build the package, what you need to do, from your home folder, is giving this commands:

    cd mypackage
    dpkg-deb –build debian

    And a debian package will be built in your mypackage folder.
    OK? Try it and report :)

    P.S.: it is easier if you install an extension to open the terminal in the folder you are viewing from your file manager. From thunar that’s simpler, just right click on the folder you are in and you can already choose the “open a terminal here” command. If on the other hand you are using nautilus, just install from synaptic or apt-get the following package:

    nautilus-open-terminal

    then killall nautilus from a terminal and next time you’ll browse with nautilus the contents of your folder, you’ll be able to right click and open a terminal directly in that folder! Nice, isn’t it ;)

  25. thank you for your reply. once again i followed all your steps throughly but got the same o/p here is the mypackage link (which is extracted wvdial package)

    http://rapidshare.com/files/227833377/mypackage.tar.gz

    if you have a time have a look at mypackage and tell me where i am going wrong :-(

    thank you for your tip “open a terminal here”. its working fine:-)

  26. http://rapidshare.com/files/227860588/mypackage.tar.gz.html

    Download this and read the readme I added inside.

  27. yahoooooo…. finally made it :-) thanks a lot man. only mistake i did was as you said wrong command (tried with same dir which you have pointed out but didnt work)…

    i request you to edit the same in your article. bcoz i dont think many people will give attention to comments…

  28. shall i post this article in my blog???

  29. If u wish, why not, as long as you link your source (this blog) ;)

  30. hi anyone say.where to get the debian packing tool,,,i searched thoughout the net but i cant.i have MAC OSX 10.5.7,windows xp,linux opensuse

    • Debian packaging tool? it has nothing to do with Mac OS, windows or opensuse, you know that? It has only to do with debian or debian derivates, like Ubuntu, etc.

  31. hi any of one htere?

  32. Is it possible to create patches in help of dpkg-deb?
    Patch – means patching existent package with ability to add another patches above or rollback already installed.

  33. Hi,
    Is it possible to create patches in help of dpkg-deb?
    Patch – means patching existent package with ability to add another patches above or rollback already installed.

  34. Thanks for the guide.
    Short and easy to follow.
    I’ve read the

    https://wiki.ubuntu.com/PackagingGuide/Basic?action=show&redirect=HowToBuildDebianPackagesFromScratch

    but after 15 minutes I still have no idea where to start at.

  35. thanks, a great guide and easy to follow. You should mention that the long description in ‘control’ needs a space at the start of the line.

  36. Thank you so much.. You saved my day :)

  37. Thats the best explenation by far! Thank you.

  38. This doesn’t work for Ubuntu 9.04 and 9.10. What’s really strange, they return different errors. md5 hashes for the Ubuntu package and my resulting package with the same contents are different. Moreover, hashes for control.tar.gz and data.tar.gz are different in these packages. Looks like the folder hierarchy is different – Ubuntu’s .tar.gz archives contain a folder called “.”, and all data is located there, while Debian keeps all data right at the archive’s root directory. Do you know any workarounds for this?

  39. Great article!I just created my first application ;)

  40. […] the .deb-file, renaming depends/python-zope-interface to depends/python-zope.interface (following nice and simple instructions). After that – no more aptitude complaints, and Chandler works […]

  41. Great guide. Now i got a .deb package to provide access to NFS shares and run remote X applications from any Debian based machine that comes across my home network. Pretty neat.

  42. Shnatsel:
    Of course the md5sum differs. It’s a .gz. Gzip embeds a timestamp of when it was gzipped into the file, so if you gzip the same data at even 1 second different times, the md5sum will differ.

  43. Great article!
    I noticed that the first folder does not need to be called lower-case “debian”. Calling it “mypackage” for example also works well, provided one then calls dpkg accordingly (i.e. dpkg-deb –build mypackage)

  44. Great tutorial! :)
    I have a .deb package that when I double click on that .deb package, after installing once, I still get “install” button instead of “reinstall” button.
    Which part of .deb package i should change to do it?

    I just want to have “reinstall” option instead of “install” option (in GDebi package installer) if I double click on my .deb package which i have already installed. Thanks

  45. […] if only I’d known where they were to go, which one belonged to /var/mqsi! Just compare it with the wealth of information regarding normal package […]

  46. […] This post is a reproduction of a tutorial that can be found here   If you enjoyed this article, please consider sharing […]

  47. thanks tips

  48. […] Dropbox Foruns   The Dark Master […]

  49. […] How to create and manipulate a deb file of a compiled application This entry was posted in Uncategorized. Bookmark the permalink. ← Forerunner 405 on Ubuntu ggarmin forerunn 405 bike mode / quick run → […]

  50. i have nokia N900 mobile and i want install some jar file in it. but as it support deb file i m not able to install it in my mobile. can i have any software for converting .jar file to .deb file. so, i can convert it and use it in my mobile.

  51. […] This post is a reproduction of a tutorial that can be found here Share this:TwitterFacebookLike this:LikeBe the first to like this post. This entry was posted on […]

  52. […] de tutoriais 1 2 […]

  53. […] _______________________________________ This post is a reproduction of a tutorial that can be found here […]

  54. […] de tutoriais 1 2 […]

  55. […] This post is a reproduction of a tutorial that can be found here Share this:TwitterFacebookLike this:LikeBe the first to like this post. This entry was posted in […]

  56. […] based operating system, using java-package. (jh_make.)PackagingGuide/Complete – Ubuntu WikiHow to create / manipulate a .deb file of a compiled application « Il Pozzo OscuroJava/Packaging – Debian Wiki[SOLVED] How can I make this setup.py better? – Ubuntu […]

  57. The longer description of the control file needs a trailing space.
    You should point this out.

  58. I just wanted to leave a huge Thank You! You really saved the day for me with this article.
    It worked right away in one time with no fuss or fiddling.

  59. Very nice website, and the information was very handy. Thank you for doing what you do.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: