Install CockroachDB on Linux

On this page Carat arrow pointing down
Warning:
As of May 10, 2022, CockroachDB v20.2 is no longer supported. For more details, refer to the Release Support Policy.

See Release Notes for what's new in the latest release, v20.2.19. To upgrade to this release from an older version, see Cluster Upgrade.

Tip:

To deploy a free CockroachDB Cloud cluster instead of running CockroachDB yourself, see the Quickstart.

Install options

Use one of the options below to install CockroachDB.

Download the binary

The CockroachDB binary for Linux requires glibc, libncurses, and tzdata, which are found by default on nearly all Linux distributions, with Alpine as the notable exception.

  1. Download the CockroachDB archive for Linux and the supporting libraries that are used to provide spatial features, and extract the binary:

    icon/buttons/copy
    $ curl https://binaries.cockroachdb.com/cockroach-v20.2.19.linux-amd64.tgz | tar -xz
  2. Copy the binary into your PATH so you can execute cockroach commands from any shell:

    icon/buttons/copy
    cp -i cockroach-v20.2.19.linux-amd64/cockroach /usr/local/bin/

    If you get a permissions error, prefix the command with sudo.

  3. Note:

    If you plan to use CockroachDB's spatial features, you must complete the following steps. Otherwise, your installation is now complete.

  4. CockroachDB uses custom-built versions of the GEOS libraries. Copy these libraries to one of the locations where CockroachDB expects to find them.

    By default, CockroachDB looks for external libraries in /usr/local/lib/cockroach or a lib subdirectory of the CockroachDB binary's current directory. If you place these libraries in another location, you must pass the location in the --spatial-libs flag to cockroach start. The instructions below assume the /usr/local/lib/cockroach location.

    1. Create the directory where the external libraries will be stored:

      icon/buttons/copy
      mkdir -p /usr/local/lib/cockroach
    2. Copy the library files to the directory:

      icon/buttons/copy
      cp -i cockroach-v20.2.19.linux-amd64/lib/libgeos.so /usr/local/lib/cockroach/
      icon/buttons/copy
      cp -i cockroach-v20.2.19.linux-amd64/lib/libgeos_c.so /usr/local/lib/cockroach/

      If you get a permissions error, prefix the command with sudo.

  5. Verify that CockroachDB can execute spatial queries.

    1. Make sure the cockroach binary you just installed is the one that runs when you type cockroach in your shell:

      icon/buttons/copy

      which cockroach
      /usr/local/bin/cockroach
    2. Start a temporary, in-memory cluster using cockroach demo:

      icon/buttons/copy

      cockroach demo

    3. In the demo cluster's interactive SQL shell, run the following command to test that the spatial libraries have loaded properly:

      icon/buttons/copy

      > SELECT ST_IsValid(ST_MakePoint(1,2));

      You should see the following output:

        st_isvalid

      true (1 row)

If your cockroach binary is not properly accessing the dynamically linked C libraries in /usr/local/lib/cockroach, it will output an error message like the one below.

ERROR: st_isvalid(): geos: error during GEOS init: geos: cannot load GEOS from dir "/usr/local/lib/cockroach": failed to execute dlopen
          Failed running "sql"
  • Keep up-to-date with CockroachDB releases and best practices:

  • Use Kubernetes

    To orchestrate CockroachDB using Kubernetes, either with configuration files or the Helm package manager, use the following tutorials:

    Use Docker

    Warning:
    Running a stateful application like CockroachDB in Docker is more complex and error-prone than most uses of Docker. Unless you are very experienced with Docker, we recommend starting with a different installation and deployment method.
    1. Install Docker for Linux. Please carefully check that you meet all prerequisites.

    2. Confirm that the Docker daemon is running in the background:

      icon/buttons/copy
      $ docker version

      If you do not see the server listed, start the Docker daemon.

      Note:
      On Linux, Docker needs sudo privileges.
    3. Pull the image for the v20.2.19 release of CockroachDB from Docker Hub:

      icon/buttons/copy
      $ sudo docker pull cockroachdb/cockroach:v20.2.19
    4. Keep up-to-date with CockroachDB releases and best practices:

    Build from Source

    1. Install the following prerequisites, as necessary:

      C++ compiler Must support C++ 11. GCC prior to 6.0 does not work due to this issue. On macOS, Xcode should suffice.
      Go Version 1.13.9+ is required, but 1.14 and above is not recommended. Older versions might work via make build IGNORE_GOVERS=1.
      Bash Versions 4+ are preferred, but later releases from the 3.x series are also known to work.
      CMake Versions 3.17.0+ are known to work.
      Autoconf Version 2.68 or higher is required.

      A 64-bit system is strongly recommended. Building or running CockroachDB on 32-bit systems has not been tested. You'll also need at least 2GB of RAM. If you plan to run our test suite, you'll need closer to 4GB of RAM.

    2. Download the CockroachDB v20.2.19 source archive, and extract the sources:

      icon/buttons/copy
      $ curl https://binaries.cockroachdb.com/cockroach-v20.2.19.src.tgz | tar -xz
    3. In the extracted directory, run make build:

      icon/buttons/copy
      cd cockroach-v20.2.19

      icon/buttons/copy
      make build

      The build process can take 10+ minutes, so please be patient.

    4. Install the cockroach binary into /usr/local/bin/ so it's easy to execute cockroach commands from any directory:

      icon/buttons/copy
      make install

      If you get a permissions error, prefix the command with sudo.

      You can also execute the cockroach binary directly from its built location, ./src/github.com/cockroachdb/cockroach/cockroach, but the rest of the documentation assumes you have the binary on your PATH.

    5. Keep up-to-date with CockroachDB releases and best practices:

    What's next?

    Note:
    By default, each node of a CockroachDB cluster periodically shares anonymous usage details with Cockroach Labs. For an explanation of the details that get shared and how to opt-out of reporting, see Diagnostics Reporting.

    Yes No
    On this page

    Yes No