thiagowfx's avatar

¬ just serendipity 🍀 (not just serendipity)

Living on Ubuntu - Instance #2 - Creating a new package

• 406 words • 2 min • updated

⚠️ This post is over one year old. It may no longer be up to date or relevant. Opinions may have changed.

These are notes from a few weeks ago when I created a sample package for Ubuntu. This article is written both as a guide and a timeline. There is no explicit tutorial here, so get your feet wet by yourself, and make sure to follow the references. Edit: enumeration became a mess here. Sorry for that.

Initial setup #

  1. Introduction; Packaging new software for Ubuntu; Debian Packaging Tutorial
  2. Get a couple of packages for packaging (duh):
shell
sudo aptitude install gnupg pbuilder ubuntu-dev-tools bzr-builddeb apt-file packaging-dev
  1. Make sure you have a PGP key.
  2. Send your PGP key to Ubuntu servers.
shell
gpg --send-keys --keyserver keyserver.ubuntu.com <KEY ID>
  1. Make sure you have a SSH key.

Building environment #

  1. Create a clean build environment:
shell
pbuilder-dist <release> create

At the time of this post, I used ’trusty’ as the release name.

  1. Make sure you have a Launchpad account.
  2. Update your Launchpad information and upload both your SSH and your GPG key into there.
  3. Identify yourself with bzr.
shell
bzr whoami "Bob Dobbs [subgenius@example.com](mailto:subgenius%40example.com)"
bzr launchpad-login subgenius

Creating the package #

  1. Start a new package, and choose its type to create a new template.
shell
bzr dh-make hello 2.7 hello-2.7.tar.gz
  1. Explore and edit the files of your new template. In particular, see the debian directory.
  2. bzr add and commit your changes. This is a DVCS such as git, so this should feel familiar.

Building and testing #

  1. Building the package:
shell
bzr builddeb -- -us -uc

The previous flags tell the system not to use GPG. -nc might also be useful: it tells the system not to start from scratch.

  1. To view the contents of a package:
shell
lesspipe *.deb
  1. To install / remove your new built package:
shell
sudo dpkg -i *.deb # attention to the architecture of your package!
sudo dpkg -r <name-of-your-package>

An alternative is to invoke sudo debi.

  1. Check for errors.
shell
lintian *.dsc *.deb

Optional testing with chroot #

  1. Next (optional; just to test the package in the chroot you have set up before, with pbuilder)
shell
bzr builddeb -S
cd ../build-area
pbuilder-dist trusty build *ubuntu*.dsc

Upload #

  1. Upload your package to Launchpad:
shell
dput ppa:<your-launchpad-username>/<your-ppa-name> *.changes

If you wanted to create a pull request instead:

shell
bzr push lp:~<launchpad-username>/+junk/hello-package

And that’s it! Then just share your PPA with your friends and clients. I hope this guide could serve to you as a quick reference of creating a new Ubuntu (or even Debian) package.