Presentation
Source packages provide you with all of the necessary files to compile or otherwise, build the desired piece of software. It consists, in its simplest form, of three files:
The upstream tarball with .tar.gz ending
A description file with .dsc ending.
A patch file, with any changes made to upstream source, plus all the files created for the Debian package. This has a .diff.gz ending.
You can use http://packages.debian.org/src:<name> for the search on source package names.
A source package could generate many .debs. To know the source package name, see the Source: field in the output of
apt-cache show package_name
If you want to know which compile-time options are enabled for a specific package (DebianPackageConfiguration), looking at the SourcePackage can be useful.
Downloading a source package
One way to obtain source packages is with
apt-get source <package name>
You need a deb-src entry in your /etc/apt/sources.list file, like :
deb-src http://http.us.debian.org/debian unstable main
A source package is downloaded in the current directory and is not installed (it will not appear in the installed package list), so you need not be root to use apt-get source. However you need root privileges or fakeroot to build the .deb.
To automatically build the DebianPackage after download, you can also use
apt-get --build source package_name
If you want to make optimized packages from source to your machine in order to possibly get faster operation, install and use apt-build (which in order uses apt-get source -b ...)
You can do a ?manual download, from http://www.debian.org/distrib/packages.en.html.
Extracting source files
Sources are normally not installed. You can only install them if you know the package name. When installing the sources of a debian package, a package ending on .dsc (description) is downloaded along with an original ?tar ball and a debian specific ?diff (compressed). The .dsc will contain the name of the package, both, in its filename as well as content (after the Source: keyword).
To unpack a source package, you can typically use :
dpkg-source -x .../path/to/filename.dsc
assuming the files filename.tar.gz and filename.diff.gz (if applicable) are present in the same directory. It unpacks into package-version, and if applicable package-version.orig, in the current directory.