10 of 10 replaced http://askubuntu.com/ with https://askubuntu.com/

#How to create a .deb file

This is a tutorial on creating a basic .deb file from a given sample script. In this tutorial first we create a sample program in bash that just show 'HELLO FROM PROGRAM'. Then we create a control file for the program in order to make a debian installer. Finally they are packaged into a .deb file.


  1. create a sample program in bash

     mkdir "$HOME/create_deb/pgmdir"
     gedit "$HOME/create_deb/pgmdir/zenity_hello.sh"

    paste the following code into it

     echo 'HELLO FROM PROGRAM' | zenity --text-info 
  2. Make the program executable

     chmod +x "$HOME/create_deb/pgmdir/zenity_hello.sh"
  3. Create control file for the debian package

    Make a file named control inside folder DEBIAN

     mkdir "$HOME"/create_deb/DEBIAN
     gedit "$HOME"/create_deb/DEBIAN/control

    and paste following details

     Package: hellodeb
     Version: 0.1
     Architecture: all
     Maintainer: totti
     Installed-Size: 6
     Depends: zenity, bash
     Section: testing
     Priority: optional
     Homepage: http://askubuntu.com
     Description: This is my first debian package.
      Guided by Totti Torvalds.
      In Description new line start with a space.

    You can edit the contents if you like. Read more about the format of this file here and here.

  4. Create postinst script, that is executed immediately after installation of the package

     gedit "$HOME"/create_deb/DEBIAN/postinst

    then paste

     set -e
     echo 'Installing program : zenity_hello.sh ......' | zenity --text-info

    and make it executable

     chmod +x "$HOME/create_deb/DEBIAN/postinst"
  5. Create prerm script, that is executed before removal of the package

     set -e
     echo 'Removing program : zenity_hello.sh ......' | zenity --text-info

    and make it executable

     chmod +x "$HOME/create_deb/DEBIAN/prerm"
  6. Make package structure and copy programs, data, etc..
    Create a structure of your installed programs and its data. In this example we put the file at /bin.

     mkdir -p "$HOME"/create_deb/bin
     cp "$HOME/create_deb/pgmdir/zenity_hello.sh" "$HOME/create_deb/bin/zenity_hello"
  7. Build the .deb file.

     dpkg-deb --build "$HOME"/create_deb .

The . will auto name the .deb file with version, arch etc. Or your custom name

    dpkg-deb --build "$HOME"/create_deb "$HOME"/create_deb/hellodeb.deb

Or if you build the .deb file with

    debuild -k'your GPG key here' -S

then you can upload it to Ubuntu Launchpad with

    dput ppa:<lp-username>/<ppa-name> packet-source.changes

like described here (source: create a .deb Package from scripts or binaries)

  1. Install the newly created .deb package. You can open it with software-center but it may not allow you to install. So I recommend to use gdebi package manager.

     sudo apt-get install gdebi
     gdebi "$HOME"/create_deb/hellodeb.deb

    Now you can install it. During installation you should see a gtk dialogue

    Installing program : zenity_hello.sh ......

  2. After installing open a terminal and type zenity_hello. If the program correctly installed and everything OK you should see a gtk dialogue


  3. Removing package

    sudo apt-get remove zenity_hello

Publish your repository in 2 minutes

As the OP wants a simple way to publish his packages I'm giving an easy hack.

requirement: dropbox (or anyother service, for ex. github) account with a public folder.

  1. Create a folder inside your Public-Dropbox-Folder where you put your *.deb Files:

     mkdir ~/Dropbox/Public/deb-packages  

    or create that folder somwhere else and put a symlink in your Public folder:

     mkdir ~/deb-packages
     cd ~/Dropbox/Public
     ln -s ~/deb-packages/ deb-packages
  2. Go into that folder and create a script that, when executed, creates the Packages.gz, containing all the needed informationen about your deb-packages. create:

     gedit import.sh  

    put this in it:

     dpkg-scanpackages . /dev/null |gzip > Packages.gz

    make it executable:

     chmod  x import.sh
  3. Copy some *.deb Files into the Folder. Could be your own or some that aren't available through other repositories. Then go into the Folder and execute the script we put there:

     cd ~/deb-packages/ 

    That should create the so called Packages.gz File, which apt looks for to know which Packages are located at this repository.

That's it

Now, wait for Dropbox to synchronize the Folder and grab the Public-URL from the Packages.gz. It should look something like this:


Get rid of the end of that link, put some more words to it and you can now use and populate the following line for the sources.list:

deb http://dl.getdropbox.../deb-packages ./

That's it you got your own deb repository running. Always synchronized locally, but available to anyone, anytime, anywhere.

NOTE: dpkg-scanpackages is available from dpkg-dev