Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am planning to write some device drivers and I need to get the Linux kernel source. My Linux kernel version is 3.2.0-23-generic-pae and I downloaded the image from this. In many of the articles I have read, it tells me that I need to have the entire kernel tree to start inserting new modules.

Is it enough if I download this image and paste it into the usr/src/ folder or do I have to do something else?

share|improve this question
I usually just install the 'linux-source' package from synaptic when I'm custom compiling for one of my machines, but given you're doing development you might need the most recent version. This link might be useful to you: – Mark Paskal Jul 5 '12 at 5:50
up vote 21 down vote accepted

This will get the source of the stock kernel:

apt-get source linux-source

You can check what version of the kernel is running like this:

uname -r

Which will print something like:


You can find a list of current source package versions available on your system via:

apt-cache search linux-source

To get the upstream version of the kernel:

git clone git://

In the above link, 'trusty' is the codename for the version of Ubuntu. You can find out the codename for the version of Ubuntu you have installed via:

cat /etc/lsb-release
share|improve this answer
+1 for the git link – RobotHumans Jul 5 '12 at 6:35
If I use git to clone how do i specify the version. Also If i Clone it is it enough if a I copy pate it into the usr/src folder – Sab Jul 5 '12 at 7:07
That git repository is kept to 3.2.0 specifically; it follows what's in Ubuntu Precise (12.04). If you want a different version change ubuntu-precise.git to ubuntu-quantal.git or whatever. It should be fine to just copy into usr/src. – Bryce Jul 5 '12 at 7:11
Okay.Thanks- But how did you find that git link? – Sab Jul 5 '12 at 7:15
Found it at – Bryce Jul 5 '12 at 7:30
apt-get source linux

is the easiest way. It will download the source from your repository - and it'll be the same as the version you're running (assuming you haven't already customised it).

But if you want to find where the source is maintained you can run:

apt-cache showsrc linux

Look for the 'Vcs-' attribute (Version control system). It'll usually be a git (Vcs-Git) or mercurial repository.

Note - these commands work with any package. Just substitute 'linux' with the package you're interested in. And also note that 'apt-get source' doesn't need sudo access and will dump the source in your current directory.

share|improve this answer
This requires the machine you are downloading on to match the target machine. Really only works if you have a network. Most of the readers landing on this page won't have a network (hence why they suddenly need the source). I need it as a tarball on a thumb drive and I don't have a working apt. – mckenzm May 16 at 20:01

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.