How to download a Debian package's source code?

19,178

Solution 1

Downloading source code from Debian repositories is as simple as running apt-get source <PACKAGE>. It will put 3 files in your current directory, .dsc that describes package, .orig.tar.gz that contains unmodified sources, and .diff.gz that contains Debian-specific changes. But if you get error E: Unable to find a source package for <PACKAGE>, then you might not have the source code repository specified, so go to /etc/apt/sources.list (or some file in /etc/apt/sources.list.d/ that contains your Debian repository), find a string like:

deb ftp://ftp.debian.org/debian wheezy main contrib non-free

Change deb to deb-src:

deb-src ftp://ftp.debian.org/debian wheezy main contrib non-free

Update package index files with sudo apt-get update and try again. See also:

Solution 2

A second possibility is to download the source code from upstream directly instead of downloading it from Debian repositories. This has the advantage that if you not only want to read the source code but might like to change something you can directly commit and submit it to upstream (assuming it is not a Debian patch).

You can usually find out the upstream source code repository URL in the file /usr/share/doc/$package_or_program_name/copyright.

$ head /usr/share/doc/git/copyright

Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Contact: [email protected]
Source: https://www.kernel.org/pub/software/scm/git/

Files: *
Copyright: © 2005-2014, Linus Torvalds and others.
License: GPL-2

Files: xdiff/*
Copyright: © 2003-2009, Davide Libenzi, Johannes E. Schindelin

This file is also referenced from packages.debian.org (search for "Copyright File").

Share:
19,178

Related videos on Youtube

Mirzhan Irkegulov
Author by

Mirzhan Irkegulov

I am a PhD student in University of Leicester, UK. My interests are functional programming, category theory, and game theory. All my contributions on the StackExchange network are placed under public domain to the extent possible by law. If you see my question or answer, and it's not good enough, for any reason, don't hesitate to leave a comment under it. I'll do my best to improve it. My goal is to leave answers that are very readable and require least background knowledge.

Updated on September 18, 2022

Comments

  • Mirzhan Irkegulov
    Mirzhan Irkegulov over 1 year

    I want to read the source code of some package in Debian; how can I do that?