This guide is for users intending to develop CockroachDB. To USE CockroachDB consult these docs instead:
- cockroachlabs.com/docs/install-cockroachdb.html
- cockroachlabs.com/docs/start-a-local-cluster.html
This is a guide for getting productive to code on CockroachDB on OS X / macOS. This assumes a blank machine/nothing is installed.
This guide will assume you are planning to develop with Bazel, which is the new build system for Cockroach. make
is currently deprecated but if the version of cockroach
you’re building is v21.2 or earlier you will probably want to use make
. In that case, see the “Building with make
" section below.
Install homebrew.
Install XCode Command Line Tools, using
xcode-select --install
Install XCode from the Mac App store and open it at least once so the developer tools can initialize. This will take a while. After installing, switch to the active developer directory:
sudo xcode-select -switch /Applications/Xcode.app && sudo xcodebuild -license accept
Install the following brew packages:
brew install git autoconf cmake bazelisk make
OS X ships with a git, but it's old. Once you install git via brew, relaunch your terminal to make sure your git version is up to date. You can confirm this by comparing the output of
which git
to the output of
echo $(brew --prefix)/bin/git
If they match, you're using brew's
git
! You also need to use brew’smake
. brew installsmake
in a special directory, so you need to update yourPATH
to look for it. On MacOS, you will need to add the following line to either~/.zshrc
,~/.bashrc
, or~/.bash_profile
depending on which shell you use.export PATH="/usr/local/opt/make/libexec/gnubin:$PATH"
Restart your shell, and confirm this directory is being used.
which make
Install Go. (Note this is not technically a requirement if all you want to do is run builds and tests via Bazel, but generally you will also want to have a toolchain installed for development.) Options include:
Official installer via clicking (don't do this)
Official installer via
brew install --cask go
(it's ok)homebrew via
brew install go
(it's ok)from source (you already know what you're doing, right?)
Clone the repo using git and navigate into it
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
Add your fork as a remote (assuming you forked cockroach on GitHub)
git remote add yourgithubusername git@github.com:yourgithubusername/cockroach.git
You should be good to start developing. Begin by running
./dev doctor
and following its suggestions to configure your workspace. When the doctor says you’re ready, you can run./dev build
to build the Cockroach binary, or./dev build short
to build the same Cockroach binary without the DB Console, which is faster to compile. See the Developing with Bazel Wiki page for more info.
Cross-compilation
These steps are only necessary if you wish to cross-compile, which requires Docker on macOS.
Ensure you have Docker installed.
brew install --cask docker
Start the docker app in the usual fashion.
Building with make
If you wish to build with make
, you should follow all the steps above, plus the following:
Install the necessary packages.
brew install node@16 yarn ccache
ccache
is not strictly necessary but will speed up C/C++ compilation when switching branches. node
and yarn
are dependencies the Bazel build will download for you but you need to have them installed globally when building with make
.