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 currently supports the following operating systems and CPU architectures.
Operating Systems |
CPU Architectures |
Compiler Toolchain |
|
|
|
Installing from Source
The following instructions are for UNIX-like systems such as GNU/Linux, FreeBSD, and Solaris. To build on Windows, see the instructions for Building on Windows.
The most recent release of libmongoc is 1.1.5 and can be downloaded here. The following snippet will download and extract the current release of the driver.
$ wget https://github.com/mongodb/mongo-c-driver/releases/download/1.1.5/mongo-c-driver-1.1.5.tar.gz $ tar -xzf mongo-c-driver-1.1.5.tar.gz $ cd mongo-c-driver-1.1.5/
Minimal dependencies are needed to build the MongoDB C driver. Optionally, if you want Kerberos (GSSAPI) or SSL support, you need to install libsasl2 and OpenSSL libraries and development headers respectively.
Make sure you have access to a supported toolchain such as GCC, Clang, SolarisStudio, or MinGW. Optionally, pkg-config can be used if your system supports it to simplify locating proper compiler and linker arguments when compiling your program.
The following will configure for a typical 64-bit Linux system such as RedHat Enterprise Linux 6 or CentOS 6. Note that not all systems place 64-bit libraries in /usr/lib64. Check your system to see what the convention is if you are building 64-bit versions of the library.
./configure --prefix=/usr --libdir=/usr/lib64
If you require SSL add --enable-ssl to the above configuration. This will require the openssl-devel on RedHat Entrprise Linux. Other Linux-based operating systems may have another name for this package such as libssl-dev on Debian.
If you require Kerberos add --enable-sasl to the above configuration. This will require the cyris-sasl-devel on RedHat Entrprise Linux. Other Linux-based operating systems may have another name for this package.
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 : yes Install man pages : yes
We can now build the driver with the venerable make program.
$ make
You can optionally build code objects in parallel using the -j option to GNU make. Some implementations of make do not support this option, such as Sun's make on Solaris 10. To build in parallel on an 8 core machine, you might use:
$ gmake -j8
To install the driver, we use make with the install target.
$ sudo make install
On systems that do not support the sudo command, we can use su -c 'make install'.
Installing on Solaris 10
MongoDB provides two ways to install the MongoDB C driver on Solaris 10. You can either build the driver yourself from a source code release, or install the precompiled binary driver as provided by MongoDB as follows.
Binary releases of the MongoDB C driver include support for both 32-bit and 64-bit architectures for both i386 and sparc.
Solaris 11 packaging is not compatible with Solaris 10. For Solaris 11, please follow the directions to build the driver yourself.
The following commands will download the most recent MongoDB binary release and install it using the pkgadd command on Solaris 10.
$ bash bash-3.2$ export ARCH=`uname -m` bash-3.2$ /usr/sfw/bin/wget --no-check-certificate "https://github.com/mongodb/mongo-c-driver/releases/download/1.1.5/MONGOmongo-c-driver-1.1.5.${ARCH}.pkg.tar.gz" bash-3.2$ gunzip -c "MONGOmongo-c-driver-1.1.5.${ARCH}.pkg.tar.gz" | tar -xf - bash-3.2$ pkgadd -d . MONGOmongo-c-driver
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 2010 Express which can be freely downloaded from Microsoft.
cd mongo-c-driver-1.1.5\src\libbson cmake -G "Visual Studio 10 Win64" "-DCMAKE_INSTALL_PREFIX=C:\mongo-c-driver"
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.1.5 cmake -G "Visual Studio 2010 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.