Why apt can't find the source code of any package?

I'm trying to download source code of certain packages, for example rhythmbox, for learning purposes. I want to do this through apt-get, with the apt-get source command.

For some reason, apt-get can't seem to find any package. I've tried several packages, and I keep getting this output from apt-get:

$ apt-get source rhythmbox
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to find a source package for rhythmbox

I've been searching for answers for quite some time now, but I can't find anyone with the same issue. apt-get works fine with installing and updating so apt-get works fine in my opinion. During the search I also learned that I had to enable the 'source code repositories' in Software Sources, so that's also enabled.

I am aware of the fact that (maybe only for certain packages, not sure) source packages can also be downloaded with bzr from Launchpad, but I want to know why this method won't work.


Solution 1:

Open the Software Center and choose Edit -> Software Sources. Which server do you use? I'm using "Server and United States" and just downloaded the source for rhythmbox just fine. I'm on Precise.

Solution 2:

apt-get source rhythmbox only works if you have the source repositories turned on, updated your package list, AND you actually have that repository in your sources.

If, for example, you installed a normal Ubuntu install and didn't add any apt repos. Then all you need to do is make sure "Source code" has a check by it. If you added extra repos, then you need to have two entries for each repo. One for "main" (usually) and one for "source".

Also just in case you haven't. Run apt-get update again to get all the new repos.

Now apt-get source installs source for the exact package you installed. This means that ifyou installed the deb from some-odd-ppa (main) then the source needs to be in some-odd-ppa(source). Packages installed from some-odd-ppa will not pull source from other repositories because it's not the same version.

I have checked and rhythmbox is available via source repositories. You simply haven't included the right source repository in your apt repos, or you haven't run apt-get update yet.