Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

What apt incantations do I need to use to download the source packages for all the installed packages into a directory? (The use case is GPL compliance when giving an installed Ubuntu system to another person along with a computer.)

share|improve this question
possible duplicate… –  Tachyons Apr 5 '12 at 13:49
You do not need to bother download all the source code for the person to be GPL compliant. It is enough that the code are publicly available. –  fossilet Apr 5 '12 at 15:36
fossilet, [citation-needed] with references to both GPLv3 text and GPLv2 text. –  hsivonen Apr 20 '12 at 11:29
Not a duplicate of the other question, since the other question is about getting the source of a single package. –  hsivonen Apr 20 '12 at 11:30

3 Answers 3

up vote 6 down vote accepted

Try this..

Create a directory where you want the source for all installed packages to be downloaded, and enter it.

mkdir source; cd source

Create a file named

dpkg --get-selections | while read line
        package=`echo $line | awk '{print $1}'`
        mkdir $package
        cd $package
        apt-get -q source $package
        cd ..

Make it executable.

chmod a+x

Execute it..


And go grab a cup of coffee :)

share|improve this answer
Thank you. This is what I was looking for. –  hsivonen Apr 20 '12 at 11:30
Glad to be of assistance (: –  SirCharlo Apr 20 '12 at 14:32

An alternative for you might be to just hand out the source CDs:

share|improve this answer
Thanks. I was browsing from and failed to locate those images. This option, of course, isn't quite correct if you've run the system update after the initial installation. –  hsivonen Apr 20 '12 at 11:32

On Ubuntu refer to command:

apt-get source package-name

it is recommended that you only use apt-get source as a regular user, because then you can edit files in the source package without needing root privileges.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.