Caution

The Packaging and Development guide is currently undergoing a major overhaul to bring it up to date. The current state you are seeing now is a preview of this effort.

The current version is unstable (changing URLs can occur at any time) and most content is not in properly reviewed yet. Proceed with caution and be aware of technical inaccuracies.

If you are an experienced packager and would like to contribute, we would love for you to be involved! See our contribution page for details of how to join in.

Get the source of a package

Before you can work on a source package you need to get the source code of that package. This article presents four ways to achieve this: git-ubuntu, pull-pkg, and apt-get source, and dget.

git-ubuntu

Note

git-ubuntu is the modern way of working with Ubuntu source packages.

Warning

git-ubuntu is still in active development and these instructions will likely change over time. While git-ubuntu will become the default packaging method, for now you may encounter rough edges or unsupported edge cases. You can ask for help in the #ubuntu-devel channel or open a bug report on Launchpad. Bug reports are very welcome!

Install

The following command will install git-ubuntu:

sudo snap install --classic --edge git-ubuntu

Basic usage

To clone a source package git repository to a directory:

git-ubuntu clone PACKAGE [DIRECTORY]

To generate the orig tarballs for a given source package:

git-ubuntu export-orig

Example

git-ubuntu clone hello
cd hello
git-ubuntu export-orig

You can find further information in these two blog articles (note that they are from 2017):

pull-pkg

The pull-pkg command is part of the ubuntu-dev-tools package and downloads a specific version of a source package, or the latest version from a specified release.

Install

The following command will install ubtuntu-dev-tools, which includes pull-pkg:

sudo apt update && sudo apt install ubuntu-dev-tools

Basic usage

pull-pkg [OPTIONS] PACKAGE-NAME [SERIES|VERSION]

You can find further information on the manual page pull-pkg(1).

Examples

There are convenience scripts that follow a similar syntax and set the OPTIONS for pull type and Distribution appropriately. Here are three examples (although there are others):

pull-lp-source

  • To download the latest version of the hello source package for the Current Release in Development from Launchpad:

    pull-lp-source hello
    
  • To download the latest version of the hello source package for the Ubuntu mantic release from Launchpad:

    pull-lp-source hello mantic
    
  • To download version 2.10-3 of the hello source package from Launchpad:

    pull-lp-source hello 2.10-3
    

pull-ppa-source

  • To download the latest version of the hello source package from the Launchpad Personal Package Archive (PPA), also called hello, of the user dviererbe:

    pull-ppa-source --ppa 'dviererbe/hello' 'hello'
    
  • To download the latest version of the hello source package for the mantic release from the same Launchpad PPA:

    pull-ppa-source --ppa 'dviererbe/hello' 'hello' 'mantic'
    
  • To download version 2.10-3 of the hello source package for the mantic release from the same Launchpad PPA:

    pull-ppa-source --ppa 'dviererbe/hello' 'hello' '2.10-3'
    

pull-debian-source

  • To download the latest version of the hello source package from Debian:

    pull-debian-source 'hello'
    
  • To download the latest version of the hello source package for the sid release from Debian:

    pull-debian-source 'hello' 'sid'
    
  • To download the version 2.10-3 of the hello source package from Debian:

    pull-debian-source 'hello' '2.10-3'
    

apt-get source

The APT package manager can also fetch source packages.

Important

Source packages are tracked separately from binary packages via deb-src lines in the sources.list(5) files. This means that you will need to add such a line for each repository you want to get source packages from; otherwise you will probably get either the wrong (too old/too new) source package versions – or none at all.

Basic usage

apt source PACKAGE-NAME

You can find further information on the manual page apt(8).

apt-get source PACKAGE-NAME

You can find further information on the manual page apt-get(8).

Example

apt source 'hello'
apt-get source 'hello'

dget

The dget command is part of the devscripts package. If you call it with the URL of a .dsc or .changes file it acts as a source package aware wget(1) and downloads all associated files that are listed in the .dsc or .changes file (debian tarball, orig tarballs, upstream signatures).

Install

sudo apt update && sudo apt install devscripts

Basic usage

dget URL

Example

Go to Launchpad and select the package you want to download (in this example; the latest version of the hello source package):

Launchpad overview page for the hello source package with an arrow pointing to the Mantic Minotaur 2.10-3 release.

Next, copy the download link of the .dsc file:

Launchpad overview page for the 2.10-3 release of the hello source package with an arrow pointing to the .dsc file link.
Finally, call dget with the copied URL:
dget https://launchpad.net/ubuntu/+archive/primary/+sourcefiles/hello/2.10-3/hello_2.10-3.dsc

Note that this works for links from Debian and Launchpad Personal Package Archives too.

You can find further information on the manual page dget(1).