How to download a Debian package’s source code?

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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 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:

Method 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: <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d6b1bfa296a0b1b3a4f8bdb3a4b8b3baf8b9a4b1">[email protected]</a>
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”).


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x