Note that at least 4GB of RAM is required to build from source and run tests.

Install prerequisites

If you are on macOS, you may find the Building from source on macOS documentation useful.

Get the CockroachDB code

Use git to fetch the source code to an appropriate location:

git clone https://github.com/cockroachdb/cockroach

If you are using make to build Cockroach, you must root your cockroach repo correctly relative to $GOPATH. Otherwise, builds will fail.

mkdir -p $(go env GOPATH)/src/github.com/cockroachdb
cd $(go env GOPATH)/src/github.com/cockroachdb
git clone https://github.com/cockroachdb/cockroach
cd cockroach

Next steps

If building with Bazel, see the Developing with Bazel documentation. Otherwise, continue reading.

(deprecated) Building with make

make is deprecated for building v22.1+ of cockroach, but still the preferred build system for v21.2 or prior.

Run make build, make test, or anything else our Makefile offers.

Note: you might need to run make clean first if you're seeing an error like 

make[1]: /usr/local/Cellar/cmake/3.13.4/bin/cmake: No such file or directory.

If you wish to reuse our builder image instead of installing all the dependencies manually, prefix the make command with build/builder.sh; for example build/builder.sh make build.

Note that the first time you run make, it can take some time to download and install various dependencies. After running make build, the cockroach executable will be in your current directory and can be run as shown in Starting with CockroachDB.

Note that if you use the builder image, you should ensure that your Docker installation grants 4GB or more of RAM to containers. On some systems, the default configuration limits containers to 2GB memory usage and this can be insufficient to build/link a CockroachDB executable.

See also Building from source on macOS