Installing the MongoDB C Driver
The following guide will step you through the process of downloading, building, and installing the current release of the MongoDB C Driver.
Supported Platforms
The MongoDB C Driver is continuously tested on variety of platforms including:
Operating Systems |
CPU Architectures |
Compiler Toolchain |
|
|
|
The driver is also known to work on FreeBSD, and should work on any POSIX compatible platform with a working c89 (or later) compiler.
Install with a Package Manager
The libmongoc package is available on recent versions of Debian and Ubuntu.
$ apt-get install libmongoc-1.0-0
For RedHat-like systems, use Remi Collet's well-maintained RPMs. Commands to enable Remi's repository and install libmongoc depend on your exact system. For example, on CentOS 6:
$ yum install http://rpms.remirepo.net/enterprise/remi-release-6.rpm $ yum install yum-utils $ yum-config-manager --enable remi $ yum update $ yum install mongo-c-driver
The Configuration Wizard for Remi's RPM Repository generates detailed instructions for your system.
Building on Unix
Prerequisites
OpenSSL is required for authentication or for SSL connections to MongoDB. Kerberos or LDAP support requires Cyrus SASL.
To install all optional dependencies on RedHat / Fedora:
$ sudo yum install pkg-config openssl-devel cyrus-sasl-devel
On Debian / Ubuntu:
$ sudo apt-get install pkg-config libssl-dev libsasl2-dev
On FreeBSD:
$ su -c 'pkg install pkgconf openssl cyrus-sasl2'
Building from a release tarball
Unless you intend on contributing to the mongo-c-driver, you will want to build from a release tarball.
The most recent release of libmongoc is 1.4.1 and can be downloaded here. The following snippet will download and extract the driver, and configure it:
$ wget https://github.com/mongodb/mongo-c-driver/releases/download/1.4.1/mongo-c-driver-1.4.1.tar.gz $ tar xzf mongo-c-driver-1.4.1.tar.gz $ cd mongo-c-driver-1.4.1 $ ./configure
If configure completed successfully, you'll see something like the following describing your build configuration.
libmongoc was configured with the following options: Build configuration: Enable debugging (slow) : no Compile with debug symbols (slow) : no Enable GCC build optimization : yes Enable automatic binary hardening : yes Code coverage support : no Cross Compiling : no Fast counters : no SASL : sasl2 SSL : yes Libbson : bundled Documentation: Generate man pages : no Install man pages : no
mongo-c-driver contains a copy of libbson, in case your system does not already have libbson installed. The configure script will detect if libbson is not installed and use the bundled libbson.
$ make $ sudo make install
Building from git
To build an unreleased version of the driver from git requires additional dependencies.
RedHat / Fedora:
$ sudo yum install git gcc automake autoconf libtool
Debian / Ubuntu:
$ sudo apt-get install git gcc automake autoconf libtool
FreeBSD:
$ su -c 'pkg install git gcc automake autoconf libtool'
Once you have the dependencies installed, clone the repository and build the current master or a particular release tag:
$ git clone https://github.com/mongodb/mongo-c-driver.git $ cd mongo-c-driver $ git checkout x.y.z # To build a particular release $ ./autogen.sh --with-libbson=bundled $ make $ sudo make install
Generating the documentation
Install the yelp-tools and yelp-xsl packages, then:
$ ./configure --enable-html-docs --enable-man-pages $ make man html
Building on Mac OS X
Prerequisites
XCode Command Line Tools
To install the XCode Command Line Tools, just type xcode-select --install in the Terminal and follow the instructions.
OpenSSL support on El Capitan
Beginning in OS X 10.11 El Capitan, OS X no longer includes the OpenSSL headers. To build the driver with SSL on El Capitan and later, first install Homebrew according to its instructions, then:
$ brew install openssl $ export LDFLAGS="-L/usr/local/opt/openssl/lib" $ export CPPFLAGS="-I/usr/local/opt/openssl/include"
Native TLS Support on Mac OS X / Darwin (Secure Transport)
The MongoDB C Driver supports the Darwin native TLS and crypto libraries. Using the native libraries there is no need to install OpenSSL. By default however, the driver will compile against OpenSSL if it detects it being available. If OpenSSL is not available, it will fallback on the native libraries.
To compile against the Darwin native TLS and crypto libraries, even when OpenSSL is available, configure the driver like so:
$ ./configure --enable-ssl=darwin
Building on OS X
Download the latest release tarball:
$ curl -LO https://github.com/mongodb/mongo-c-driver/releases/download/1.4.1/mongo-c-driver-1.4.1.tar.gz $ tar xzf mongo-c-driver-1.4.1.tar.gz $ cd mongo-c-driver-1.4.1
Build and install the driver:
$ ./configure $ make $ sudo make install
Generating the documentation on OS X
Homebrew is required to generate the driver's HTML documentation and man pages:
$ brew install yelp-xsl yelp-tools $ ./configure --enable-html-docs --enable-man-pages $ make man html
Installing on Mac OS X
To build the C Driver on a Mac, install the prerequisites in order to build it from source. It is recommended to use Homebrew:
$ brew install automake autoconf libtool pkgconfig
Additionally, XCode is required. The driver can then be installed by following the directions for building from source.
Building on Windows
Building on Windows requires Windows Vista or newer and Visual Studio 2010 or newer. Additionally, cmake is required to generate Visual Studio project files.
Let's start by generating Visual Studio project files for libbson, a dependency of the C driver. The following assumes we are compiling for 64-bit Windows using Visual Studio 2015 Express, which can be freely downloaded from Microsoft.
cd mongo-c-driver-1.4.1\src\libbson cmake -G "Visual Studio 14 2015 Win64" "-DCMAKE_INSTALL_PREFIX=C:\mongo-c-driver"
(Run cmake -LH . for a list of other options.)
Now that we have project files generated, we can either open the project in Visual Studio or compile from the command line. Let's build using the command line program msbuild.exe
msbuild.exe ALL_BUILD.vcxproj
Now that libbson is compiled, let's install it using msbuild. It will be installed to the path specified by CMAKE_INSTALL_PREFIX.
msbuild.exe INSTALL.vcxproj
You should now see libbson installed in C:\mongo-c-driver
Now let's do the same for the MongoDB C driver.
cd mongo-c-driver-1.4.1 cmake -G "Visual Studio 14 2015 Win64" "-DCMAKE_INSTALL_PREFIX=C:\mongo-c-driver" "-DBSON_ROOT_DIR=C:\mongo-c-driver" msbuild.exe ALL_BUILD.vcxproj msbuild.exe INSTALL.vcxproj
All of the MongoDB C Driver's components will now be found in C:\mongo-c-driver.
Native TLS Support on Windows (Secure Channel)
The MongoDB C Driver supports the Windows native TLS and crypto libraries. Using the native libraries there is no need to install OpenSSL. By default however, the driver will compile against OpenSSL if it detects it being available. If OpenSSL is not available, it will fallback on the native libraries.
To compile against the Windows native TLS and crypto libraries, even when OpenSSL is available, configure the driver like so:
cmake -G "Visual Studio 14 2015 Win64" "-DENABLE_SSL=WINDOWS" "-DCMAKE_INSTALL_PREFIX=C:\mongo-c-driver" "-DBSON_ROOT_DIR=C:\mongo-c-driver"