./dev tool for convenience.
Prerequisites
Before building CockroachDB from source, ensure you have the required dependencies installed.Install Dependencies
Follow the bootstrap script for your platform:This installs:
Debian/Ubuntu
- Go (correct version as specified in the project)
- Bazel build system
- Required development libraries
The
./dev tool automatically builds itself on first run. It uses Bazel internally and caches the binary at bin/dev-versions/dev.$VERSION.Building the CockroachDB Binary
The./dev build command is the primary way to build CockroachDB components.
Full Binary with UI
artifacts/cockroach.
Short Build (Recommended for Development)
Building Specific Packages
Build Options and Flags
The./dev build command supports various options:
Common Build Scenarios
Cross-compilation
Cross-compilation
Build for different platforms:Cross-compiled binaries are placed in the
artifacts/ directory.Building with GEOS libraries
Building with GEOS libraries
For geospatial support:This builds both the cockroach binary and required libgeos libraries.
Docker image builds
Docker image builds
To build a deployment Docker image:
-
Build the cross-compiled binary:
-
Copy artifacts to deploy directory:
-
Build the Docker image:
Using the Bazel Builder Container
For consistent builds across platforms, use thebazelbuilder Docker container:
Ensure Docker grants at least 4GB of RAM to containers. The default 2GB limit may be insufficient for building CockroachDB.
Build Performance Tips
Incremental Builds
Bazel performs incremental builds automatically. Subsequent builds only recompile changed components.
Remote Cache
CockroachDB uses remote caching for Bazel. Most dependencies are pre-cached, speeding up initial builds.
Build Short
Use
./dev build short instead of full builds during development. It’s 3-5x faster.Specific Packages
Build only the packages you’re working on rather than the entire binary.
Troubleshooting Build Issues
Build Fails with Memory Errors
Increase Docker memory allocation or reduce parallelism:Stale Build Artifacts
Clean and rebuild:Missing Dependencies
Re-run the bootstrap script:Next Steps
Running Tests
Learn how to run the test suite
Code Structure
Understand the codebase organization
Contributing
Read the contribution guidelines
Code Generation
Learn about generated code