Building Hadoop from source means compiling the Apache Hadoop repository with Maven, producing the distribution artifacts, and optionally installing them into your local Maven repository. The core condition is a Java JDK and Maven matched to your chosen Hadoop release line: Hadoop 3.x still has code paths that expect Java 8, while some newer build profiles and dependencies behave differently on Java 11 and later. The exact JDK baseline, Maven version, and module flags move with the branch, so pin a release tag and read that tag's BUILDING.txt before you run anything. The steps below cover prerequisites, checkout, build commands, verification, common failures, and platform-specific traps.
Prerequisites Before You Download the Tree
Hadoop is a multi-module Maven project. A source build is not a single compile: the root reactor builds dozens of modules, including native code wrappers, protocol buffers generation, and shaded client jars. Because of that, a partial toolchain produces confusing failures deep into the build rather than clean early errors.
Required toolchain
A 64-bit JDK. Hadoop release lines historically target Java 8, and Hadoop 3.x branches document Java 8 as the baseline while adding Java 11 support in later releases. Confirm the branch's documented JDK on the tag you intend to build rather than assuming. Maven, Apache's build tool. Hadoop's BUILDING.txt states a minimum Maven version per branch, and the enforcer plugin in the root POM will reject older versions. A C/C++ compiler and CMake for native modules, plus the usual native library headers. If you only need Java jars and client libraries, you can skip native code, but the default profile set may still try to build it. Protocol Buffers compiler matching the version pinned in the branch's POM, if you intend to regenerate .proto sources. Pre-generated sources exist for release tags, so this is often optional for plain builds. Adequate disk and RAM. The reactor's dependency downloads and target directories are large, and parallel builds consume several gigabytes of heap.
Recommended extras
git for checkout and easy branch switching. wget or curl for fetching the matching protoc binary if needed. On macOS, the Xcode command line tools; on Linux, a package group such as build-essential plus zlib and openssl development headers; on Windows, a POSIX layer such as WSL or Cygwin is the practical route because Hadoop's shell scripts and some plugins assume a Unix-like environment.
One more prerequisite is patience with the first run. Maven downloads a large dependency graph on a clean machine; subsequent builds reuse the local repository and speed up sharply.
Check Out the Right Tag and Configure the Build
Working from a release tag is safer than from a moving branch head. A tag corresponds to a published release whose BUILDING.txt, POM versions, and dependency pins were tested together.
1: Clone the repository: git clone (or your mirror). 2: Enter the directory and list tags with git tag. Hadoop tags follow a pattern like rel/release-3.3.6. 3: Check out the tag you want: git checkout rel/release-3.3.6. Detached HEAD is expected and fine for a build. 4: Open BUILDING.txt at the repository root and read the "Requirements" and "Build" sections for that tag. This file is the authoritative, version-specific instruction set and supersedes any generic guide, including this one, where they disagree. 5: Inspect pom.xml for the maven.compiler.source and target properties and the enforcer plugin's Java rule. These tell you the JDK baseline the branch expects. 6: Optionally create a settings file or environment variables for a custom local repository if you want to isolate this build from other Maven work: -Dmaven.repo.local=/path/to/repo.
At this point, decide your scope. A full mvn install -DskipTests builds every module and installs artifacts locally. A narrower build such as mvn install -DskipTests -pl hadoop-client-modules/... compiles only what you need, but module coordinates move between versions, so confirm paths against the tag's directory listing.
Build the Distribution Step by Step
The commands below assume a Unix-like shell in the repository root. On Windows, run them inside WSL for the least friction.
1: Verify versions: java -version and mvn -version. Both must satisfy the tag's requirements, and JAVA_HOME must point at the JDK you intend to use. 2: Set memory for Maven if needed: export MAVEN_OPTS="-Xmx4g". Large reactors can exhaust the default heap. 3: Run the build: mvn clean install -DskipTests -Dmaven.javadoc.skip=true. 4: Watch for the "BUILD SUCCESS" line and for the reactor summary at the end. A failure mid-reactor stops the build and names the failing module. 5: Find the assembled distribution under hadoop-dist/target/. The tarball name includes the version, for example hadoop-3.3.6.tar.gz, alongside an unpacked hadoop-3.3.6 directory. 6: Optionally run a smoke test: unpack the tarball, then run bin/hadoop version from its root. That command exercises the shell scripts, classpath assembly, and native library loading without needing a cluster.
What to expect on a first clean build: a long dependency download phase, a compile phase that takes minutes to tens of minutes depending on hardware and parallelism, and native module builds that may be skipped if the platform profile does not match. Success is the reactor summary listing every module as SUCCESS and the distribution tarball appearing in hadoop-dist/target.
If you also plan to build downstream projects against these artifacts, use install rather than package. install places Hadoop jars and POMs in your local Maven repository so other projects can depend on the exact version you built.
Verify the Build Actually Works
A green reactor is necessary but not sufficient. Verification should confirm three things: the artifacts exist where expected, the distribution runs its own CLI, and the version string matches the tag you checked out.
Confirm the tarball and unpacked directory exist under hadoop-dist/target/. Run bin/hadoop version inside the unpacked distribution and read the reported version. It must equal the tag's version. Run bin/hdfs version and, if YARN modules built, bin/yarn version. Missing commands usually mean a module was skipped or a build profile excluded it. List the jars in share/hadoop/common/ and check that the shaded client jar is present. This is the artifact most client applications rely on. If native code built, confirm the lib/native directory contains the expected .so or .dylib files. Their absence is not fatal for a Java-only workflow but changes compression and performance behavior.
A simple success check: a fresh shell in the unpacked distribution can run hadoop version with no environment variables set beyond JAVA_HOME. If that works, the assembled configuration and classpath are internally consistent.
Understand What Each Build Flag Does
Build flags are where most confusion originates, because a flag that helps one workflow breaks another. Treat them as deliberate choices, not defaults to copy.
-DskipTests versus -Dmaven.test.skip
-DskipTests compiles tests but does not run them. -Dmaven.test.skip=true skips compiling and running them. Use the second when you want the fastest artifact build and do not intend to run the project's test suite. Use the first if you may later run tests without a recompile.
-Dmaven.javadoc.skip=true
Javadoc generation is slow and can fail on doclint warnings that are harmless for your purpose. Skipping it is standard for local builds; publish pipelines should not skip it.
-Pdist and the distribution module
Hadoop's distribution assembly lives in a dedicated module. In several branches the dist profile controls whether the tarball is assembled, and in others the hadoop-dist module is part of the default reactor. Check the tag's BUILDING.txt for which applies before assuming a flag is needed.
-Drequire. flags and native profiles
The build can require optional native libraries or use bundled ones. These profile flags change which native bindings are compiled in. If you see enforcer failures naming a native library, that is a profile/requirements mismatch, not a code bug.
-T for parallel builds
mvn -T 1C ... builds with one thread per core. It speeds up large reactors but can obscure the true failing module in logs and occasionally exposes ordering issues in plugin executions. Use it after a first successful serial build, not before.
Offline mode
-o runs Maven without network access. It only works once the full dependency graph is cached, so it is a second-build optimization, not a first-build strategy.
Troubleshooting Build Failures and Stop Conditions
Symptoms in a Hadoop source build usually map to a small set of causes. Work through reversible checks first and avoid "fixing" the code tree unless you have a specific reason.
Symptom: enforcer plugin fails immediately with a Java version message. Cause: your JDK does not match the branch's declared baseline. Check: read the enforcer rule in the root POM and the JDK requirement in BUILDING.txt. Switch JAVA_HOME to a matching JDK. This is reversible and fast.
Symptom: Maven version rejected at startup. Cause: Maven older than the branch minimum. Check: mvn -version against BUILDING.txt. Upgrade Maven rather than editing the POM.
Symptom: protoc not found or generated sources missing. Cause: a module that regenerates protobuf sources cannot find a matching compiler. Check: the protobuf version pinned in the POM versus the protoc on your PATH. Install the matching version. Most release-tag builds include pre-generated sources, so this often indicates a profile or cleanup issue rather than a hard requirement.
Symptom: native compile errors in C/C++ modules. Cause: missing headers, mismatched CMake, or an unsupported compiler. Check: the native build log for the first error, not the cascade. Installing development headers for zlib and openssl resolves many Linux cases. If the platform is not supported by the branch's native profile, skipping native modules for a Java-only build is a valid fallback.
Symptom: OutOfMemoryError during compile or test-compile. Cause: insufficient Maven or forked compiler heap. Check: raise MAVEN_OPTS. For forked compilers, the module POM may set its own heap; do not edit it unless you are prepared to diverge from the tag.
Symptom: dependency resolution fails with checksum or 403 errors. Cause: network, proxy, or mirror configuration. Check: your Maven settings.xml mirrors and proxy settings. A corporate proxy is the usual culprit; the build itself is fine.
When to stop and seek help: if you encounter failures in shaded jar creation, plugin classloader conflicts, or signature/checksum verification that persist after a clean local repository rebuild, and the same tag builds for others, the remaining work is environment forensics. At that point, consult the project's issue tracker and mailing list with the exact command, JDK, Maven, OS, and full failing module log rather than modifying POM files speculatively. If you are building for a regulated or production deployment, have your platform team validate the resulting artifacts and their provenance rather than treating a local build as release-grade.
Platform and Version Differences That Change the Recipe
Because Hadoop's build spans many years of Java and native tooling evolution, the same command can succeed on one release line and fail on another. Keep these differences in mind.
Java version. Hadoop 3.x releases document Java 8 as the runtime baseline, with later releases adding Java 11 support. Building on a JDK newer than the branch declares is the single most common source of enforcer and bytecode failures. If you must use a newer JDK, verify the tag documents it.
Maven version. The minimum Maven requirement rises over time as plugins mature. An older Maven can appear to start fine and then fail in a plugin that requires newer APIs.
Native libraries. Hadoop's native code covers compression, checksums, and filesystem acceleration. Whether these build depends on platform profiles and available headers. A Java-only distribution is legitimate for development and client work; production filesystem and compression behavior may differ without native libraries.
Windows. Hadoop's shell scripts, path handling, and some tests assume Unix. WSL is the pragmatic route. A native Windows build is possible in some branches but is not the path of least resistance.
Protocol Buffers. The pinned compiler version matters because generated Java must match the runtime library version. Mismatches surface as runtime NoSuchMethodError or serialization failures, not compile errors, so verify the pair.
Distribution contents. Which modules land in the tarball and which jars are shaded can change between minor releases. Read the tag's assembly descriptors rather than relying on a remembered layout.
What "Built From Source" Does and Does Not Give You
A source build produces jars and a distribution that match the tag's code. It does not give you a tested release binary with the project's release engineering checks, and it does not give you a supported deployment. Those are different things.
What you get: reproducible artifacts from a known commit, the ability to patch and rebuild, local Maven artifacts for downstream development, and a distribution you can run in single-node or pseudo-distributed mode for development.
What you do not get: release signing and checksum provenance, cross-platform validation, security patch backports beyond the tag, or a support contract. If you need those, use the official release binaries and verify their signatures.
A worked size expectation, labeled as illustrative: a full reactor build with tests skipped typically produces a distribution tarball in the hundreds of megabytes because it bundles many jars and native artifacts. The exact size varies by version and included modules; check hadoop-dist/target after your build rather than treating any figure as canonical.
For downstream use, the practical payoff of install is that a project with a dependency on org.apache.hadoop:hadoop-client at your built version resolves to your local artifact. That is useful for testing patches; it is also a trap if teammates expect the published artifact with the same version string. Use a distinct version suffix in your local build if you plan to share code that depends on it.
FAQ
Can I build only the client jars instead of the whole distribution?
Yes. Use Maven's module selection to build the client modules and their dependencies, then take the shaded client jar. Module paths and artifact coordinates vary by version, so confirm them against the tag's directory structure and POMs before running the command.
Do I need Protocol Buffers and CMake for a Java-only build?
Often no. Release tags include pre-generated protobuf sources, and native modules can be skipped when the platform profile does not apply. Read BUILDING.txt for the tag to confirm which requirements are mandatory versus profile-dependent.
Why does the build work on one machine and fail on another with the same command?
Usually JDK or Maven version differences, native headers, proxy or mirror configuration, or a stale local Maven repository. Compare java -version, mvn -version, and settings.xml before comparing the source tree, and try a clean local repository as a reversible check.
Is a locally built distribution safe to run in production?
Treat it as a development artifact. It lacks release signing and the project's release validation. For production, use official release binaries with verified signatures and your organization's change control.