Docs Menu

Docs HomeC++ Driver

Installation on macOS

On this page

  • Step 1: Choose a C++17 polyfill
  • Step 2: Download the latest version of the mongocxx driver
  • Step 3: Configure the driver
  • Step 4: Build and install the driver

First, choose a C++17 polyfill library.

The most reliable starting point for building the mongocxx driver is the latest release tarball.

The mongocxx releases page will have links to the release tarball for the version you wish you install. For example, to download version 3.10.1:

curl -OL https://github.com/mongodb/mongo-cxx-driver/releases/download/r3.10.1/mongo-cxx-driver-r3.10.1.tar.gz
tar -xzf mongo-cxx-driver-r3.10.1.tar.gz
cd mongo-cxx-driver-r3.10.1/build

Make sure you change to the build directory of whatever source tree you obtain.

Without additional configuration, mongocxx installs into its local build directory as a courtesy to those who build from source. To configure mongocxx for installation into /usr/local as well, use the following cmake command:

cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DMONGOCXX_OVERRIDE_DEFAULT_INSTALL_PREFIX=OFF

These options can be freely mixed with a C++17 polyfill option. For instance, this is how a user would run the command above with the Boost polyfill option:

cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DBSONCXX_POLY_USE_BOOST=1 \
-DMONGOCXX_OVERRIDE_DEFAULT_INSTALL_PREFIX=OFF

Build and install the driver:

cmake --build .
sudo cmake --build . --target install

The driver can be uninstalled at a later time in one of two ways. First, the uninstall target can be called:

sudo cmake --build . --target uninstall

Second, the uninstall script can be called:

sudo <install-dir>/share/mongo-cxx-driver/uninstall.sh
←  Installation on WindowsInstallation on Linux →