Making application submissions and publishing easier for developers is knowing how to package your software for the Ubuntu Software Center. One of greatest things about Ubuntu is the simplicity and reliability of installing software with Debian packages and apt. Ubuntu uses the same system to deliver software through the Ubuntu Software Center. The packaging tools described below were written for Debian developers working and integrating upstream Linux projects. Some parts can be tricky and many developers are working hard to automate most of your packaging experience with a new service aptly named pkgme. However, that service is not quite ready today so please read on!
Debian and Ubuntu organize software into packages. These packages have a specific format which end in .deb. The .deb package is an archive that holds the binary or source of the application along with metadata describing the location to copy the application and it’s supporting files. Many different methods exist for creating Debian packages, however in the example below debhelper is our tool of choice.
The example provided is a how to step by step guide to create a Debian source package from a compiled application which will install into /opt/<appname>, add a desktop file and icon into the global menu for launching the application, and submit it for publishing under the Ubuntu App Developer Program.
Ubuntu Software Center expects all application files to be installed into /opt/<appname>. Configuration and user data files should reside in ~/.config/<appname>. With those requirements in mind, the example below has been tested and will run in /opt/<appname> without any problems.
Prerequisites for these instructions
- Ubuntu 11.10 or later.
- The example application to package: download Dungeon Adventure Game › or learn more about it
- Packaging tools: you can install them in Ubuntu by opening a terminal with Ctrl+Alt+T and typing the following command
sudo apt-get install devscripts build-essential lintian dh-make
Getting ready to package
Setting up the directory structure
- Create the top dir. Create a directory to work in first. We want to package the Dungeon Adventure Game app, so we’ll choose a fitting name for it: dungeon – Make a directory called dungeon using mkdir dungeon
- Create the packaging dir. In the new dungeon directory create another directory to place the package files you’ll be creating. The name of this directory should coincide with the version of the package using a dash between the package name and the package version. The resulting directory is dungeon/dungeon-1980.0
- Create the original files dir. In the new dungeon-1980.0 directory extract the downloaded archive into a new dungeon_1980 subdirectory.
Setting up the desktop file
Now that the file structure is complete, you’ll need to create what is called a Desktop file. A desktop file contains information on how to execute an application and on its associated icon. It will enable users to see your app’s icon in the Unity Launcher and in the Unity Dash, and to launch it from there.
- Desktop file. Create a file named dungeon.desktop with your text editor of choice and save it in the <code>dungeon-1980.0</code> directory. Copy the content below and save it.
- Icon. Create an icon named <code>desktop.png</code> and save it in the same <code>dungeon-1980.0</code> directory. You can use the example 48 x48 pixel image below.
[Desktop Entry] Type=Application Version=1.0 Name=Dungeon Adventure Comment=Dungeon Adventure Game (a.k.a. Zork) Icon=dungeon Exec=gnome-terminal --window -e '/opt/adventure/dungeon’ Path=/opt/dungeon Categories=Games;
You’ve just finished creating the directory layout and file needed for the packaging tools to work. After having followed the steps above, your file structure should look like this:
Now onto the fun stuff: actually packaging your app.
Packaging fun: debianizing the package
- Create the package control files. In the dungeon/dungeon-1980.0/ directory run dh_make -n (for our example we will build as a native package hence the -n option). The dh_make command will create the debian directory and populate the example templates. At the prompt for the Type of package, select s for Single binary. Now change into the debian directory.
- Remove unnecessary files. For this application, in the debian directory remove all files with the .ex and .EX extensions and all README.* files as they are not needed for the native application being built.
- Create the installation script. During installation of the application the files need to be copied into the /opt/dungeon directory. Edit (create a new file) dungeon/dungeon-1980.0/debian/install adding the lines below to place the files in their proper location during installation.
dungeon_1980/* opt/dungeon dungeon.desktop usr/share/applications dungeon.png usr/share/icons/dungeon.png
Now you are ready to build the package
Packaging fun: building the package
- Update the changelog. Ensure you are in the dungeon/dungeon-1980.0/ directory and run dch to update the changelog. For an intial release you can simply have one entry that shows * Initial Release along with your name and email address. The package name at the top of the changelog should be “dungeon (1980.0)”
- Build the binary package. From the dungeon/dungeon-1980.0 directory run debuild -b to build the binary package. This will create a number of lintian (lintian is a sanity check tool for the package) errors. Disregard them for this example, but do fix these errors in your real submission.
- Check out the output. The output is a file named dungeon_1980.0_i386.deb (if a amd64 app was being created the extension will have _amd64.deb)
- Install and verify the binary package. In order to verify the build worked run sudo dpkg -i dungeon_1980.0_i386.deb to install the .deb built in the previous step, check the files are all where we expected them (/opt/dungeon, /usr/share/applications) and run the Dungeon Adventure by clicking on the Dash icon and typing Dungeon to show the icon for the app. Don’t get distracted here – this game is addictive.
- Remove the binary package. Once the install is verified remove the installed package (if you wish) using dpkg --purge dungeon
- Create the source package. The final step is to create the Debian source package for submission via MyApps. cd to the dungeon/dungeon-1980.0 directory and run debuild -S the -S is for source package and creates a .dsc file (among others).
- Archive the source package. Provided no errors appeared in the build process tar up the files found in the dungeon/ directory as the Debian source tar cxf dungeon-1980.0-debsrc.tar.gz *.dsc *.changes *.tar.gz from the working directory (dungeon/)
- Submit to MyApps. That’s it! Submit the debian source package tar created in step 7 to our Developer Program or MyApps!
Follow us on Twitter @ubuntuappdev and give us feedback!
- debuild man page
- dpkg-buildpackage man page
Follow Ubuntu App Development on: