Getting Source of an Installed Package on Ubuntu
This is a little tutorial that goes over how to find a system installed python application, find out what package it comes from, and get the source and package build information. This can be useful for a variety of reasons from looking at how to package specific types of application or just to see the source of the application you are running. This is done on Ubuntu, but would work on any Debian based distribution.
Lets hop on over to /usr/bin and see what runs python in a very simple way.
cd /usr/bin grep /usr/bin/python * 2to3:#! /usr/bin/python2.7 2to3-2.7:#! /usr/bin/python2.7 2to3-3.5:#! /usr/bin/python3.5 add-apt-repository:#! /usr/bin/python3 alacarte:#! /usr/bin/python -OOt apport-cli:#!/usr/bin/python3 apport-unpack:#!/usr/bin/python3 apt-add-repository:#! /usr/bin/python3 aptdcon:#! /usr/bin/python3 apturl-gtk:#!/usr/bin/python3 chardet3:#! /usr/bin/python3 chardetect3:#! /usr/bin/python3 check-language-support:#! /usr/bin/python3 createfontdatachunk:#! /usr/bin/python3 createfontdatachunk.py:#! /usr/bin/python dcut:#!/usr/bin/python debmake:#!/usr/bin/python3 ...
The list goes on and on. We can see there's a mixture of python2 and python3 apps on my system. Now, lets pick out one of those /usr/bin files, particularly /usr/bin/alacarte and see what package it comes from.
dpkg -S /usr/bin/alacarte alacarte: /usr/bin/alacarte
Before we can download the source, we need to make sure we have source repositories enabled in apt. These are usually not enabled by default, but your mileage may vary.
sudoedit /etc/apt/sources.list
Uncomment the source lines for the main release. For me, that's this line.
deb-src http://us.archive.ubuntu.com/ubuntu/ xenial main restricted
Save and exit. Now, update.
sudo apt-get update
Now, get the source.
cd ~ apt-get source alacarte
Notice no sudo on the apt-get source. This results in the following files and directory being download to the current working directory containing all of the application source and package source. From here you can inspect their contents.
alacarte-3.11.91
alacarte_3.11.91-2.debian.tar.xz
alacarte_3.11.91-2.dsc
alacarte_3.11.91.orig.tar.xz