Linux Source Code Download: Where to Get It and What to Do
Downloading the Linux kernel source code is straightforward once you know where to look, but most guides skip the part about what you're actually getting and why it matters.

Where the source code actually lives
The canonical home for Linux kernel source code is kernel.org, maintained by the Linux Kernel Organization, a public benefit corporation that exists specifically to host this code. Every official release, every release candidate, every long-term support branch, all of it lives there. It's the first place you should go, and honestly the only place you need.
That said, a mirrored copy lives on GitHub at github.com/torvalds/linux. Linus Torvalds pushes to that repository himself. It's a read-only mirror of the main repository at kernel.org, not the authoritative source, but it's extremely useful if you prefer GitHub's interface for browsing code or you want to clone over HTTPS without dealing with kernel.org's git infrastructure. The two are functionally identical for most purposes.
There's also git.kernel.org, which hosts the actual development trees, including subsystem trees maintained by individual maintainers. If you're serious about following net-dev, drm-next, or any other subsystem, that's where those branches live.
How to download the source code: your three options
1. Download a tarball from kernel.org
Go to kernel.org. The front page shows you a table of the latest stable, longterm, and mainline releases. Pick the version you want and click the yellow "tarball" button. You'll get a .tar.xz file, typically around 130-140 MB compressed. Unpack it with:
tar -xvf linux-6.x.x.tar.xz
The uncompressed tree lands somewhere around 1.3 to 1.5 GB, depending on the version. That's the full source, every driver, every architecture, every filesystem, everything. No history, just the snapshot of that release.
This is the right approach if you're building a custom kernel or just want to read the code without needing git history. It's fast, simple, and self-contained.
2. Clone the Git repository
If you want the full history or you plan to track ongoing development, clone the repository instead:
git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Or, using GitHub's mirror:
git clone https://github.com/torvalds/linux.git
Fair warning: the full git clone with history is large. The object database alone runs over 4 GB. If you only need the latest commit and don't care about history, use a shallow clone:
git clone --depth=1 https://github.com/torvalds/linux.git
That gets you just the current HEAD and cuts the download to roughly 200-300 MB. Fast, practical, and sufficient for most reading or build purposes.
3. Get the source for your running kernel (distro users)
If you're running Ubuntu, Fedora, Debian, or another mainstream distribution and you just need the kernel source that matches your current installation, your package manager handles this for you.
On Debian or Ubuntu:
apt-get source linux-image-$(uname -r)
Or, to install kernel headers for module building (which is usually all you actually need):
sudo apt install linux-headers-$(uname -r)
On Fedora or RHEL-based systems:
sudo dnf install kernel-devel
These packages are patched versions of the upstream kernel source. Distributions carry their own patches on top of Torvalds' tree, so the code you get this way won't be byte-for-byte identical to what kernel.org serves. For driver development or module compilation against your running kernel, this is the right path. For studying upstream Linux, use kernel.org.
Which version should you pick? kernel.org marks releases as "stable," "longterm," or "mainline." Stable and longterm (LTS) releases receive ongoing security and bug-fix backports. Mainline is Torvalds' active development tree. For learning or building a personal system, a stable or LTS release is the practical choice. The kernel release documentation explains the support timeline for each.
What's actually inside the source tree
People download the Linux source code and then stare at 80,000 files and don't know where to start. Here's a quick map of the top-level directories that matter:
- arch/: Architecture-specific code. x86, arm64, riscv, mips, and about 25 others. If you're running a typical PC,
arch/x86is your world. - drivers/: The biggest directory by far. More than half the kernel source is device drivers. Graphics, networking, USB, storage, all of it lives here.
- fs/: Filesystem implementations. ext4, btrfs, xfs, tmpfs, procfs, everything.
- kernel/: Core scheduling, locking, tracing, signals. The actual guts of the OS.
- net/: Networking stack. TCP/IP, netfilter, Bluetooth protocols.
- mm/: Memory management. Virtual memory, page allocation, the OOM killer.
- include/: Header files. Shared across the tree.
- Documentation/: Surprisingly good documentation, especially for newer subsystems.
- tools/: Userspace tools that live alongside the kernel, like perf.
The official kernel documentation hosted at kernel.org is the best reference for understanding what's in these directories and how to actually build the kernel once you have the source.
How to get source code for other programs on Linux
The question "how to get source code in Linux" often means something different from fetching the kernel itself. On any Debian or Ubuntu system, almost every package in the repository has a corresponding source package. The apt-get source <package-name> command downloads the upstream source tarball plus any distribution patches and unpacks them in your current directory. You need deb-src lines in your /etc/apt/sources.list for this to work.
For Fedora and its derivatives, dnf download --source <package-name> fetches the source RPM. You can then install it and find the contents under ~/rpmbuild/SOURCES/.
For software that's developed in the open (which is most of it), the quickest method is often just cloning the project's own Git repository directly. The guides on It's FOSS cover working with Git on Linux in a way that's genuinely accessible if you haven't done much version control before.
How to install and build the Linux kernel from source
Getting the source is step one. Building it is another matter entirely, and it's not something to do carelessly on a production machine. Here's the short version of the process:
Install build dependencies
On Ubuntu or Debian:
sudo apt install build-essential libncurses-dev bison flex libssl-dev libelf-dev
Configure the kernel
From inside the unpacked source directory, run:
make menuconfig
This opens a terminal UI where you select what to compile in. If you want to start from your current system's config rather than starting from scratch:
cp /boot/config-$(uname -r) .config
make olddefconfig
Compile
make -j$(nproc)
The -j$(nproc) flag uses all available CPU cores. On a modern 8-core machine, a full build from scratch takes 20-40 minutes. On a 4-core machine, expect 45-90 minutes. A second build after a small change is much faster because only changed files recompile.
Install
sudo make modules_install
sudo make install
Then reboot and select your new kernel from the GRUB menu. If something goes wrong, the old kernel is still there to boot into. This is one reason you should never delete your working kernel before confirming the new one boots. Our guide on how to install Linux covers GRUB and boot management concepts that are useful context here.
Where to download Linux for free (the distro question)
If you're asking "where can I download Linux for free" and you actually mean a complete operating system rather than just the kernel source, the answer is that every major Linux distribution is free to download. Ubuntu is at ubuntu.com, Fedora at fedoraproject.org, Debian at debian.org. There are no legitimate paid download gates for these. The kernel source at kernel.org is also completely free, released under the GPL v2 license.
The GPL license is significant. It means anyone who receives the kernel in binary form has the right to request the source code. This is why hardware vendors shipping Linux-based devices are required to make their kernel source available. The full text of GPL v2 at gnu.org is worth at least skimming if you work with kernel code professionally.
Reading the source without downloading it
Downloading gigabytes of source is overkill if you just want to read a specific file or understand how a system call works. Two tools make this easy:
Bootlin's Elixir cross-referencer at elixir.bootlin.com lets you browse any version of the kernel source in a browser with symbol cross-referencing. You can click any function name and immediately see every place it's defined and called. It's the single best tool for navigating unfamiliar kernel code without having a local clone.
GitHub at github.com/torvalds/linux also works for casual reading and has a reasonable search function for small queries, though it doesn't match Elixir for serious code exploration.
If you do have a local clone and want fast symbol search, ctags or cscope built from the source directory are the traditional approaches. The Documentation/process directory inside the kernel tree has a file called coding-style.rst that reads quickly and gives you a real sense of how the project is organized and what its maintainers value.
The Linux kernel is somewhere around 28 to 30 million lines of C and assembly as of 2024, making it one of the largest open source codebases in existence. You're not going to read all of it. Pick a subsystem that matches something you actually care about and start there.