Installing Prebuilt MongoDB C Driver Libraries
On this page
The libmongoc
and libbson
libraries are often available in the package
management repositories of common Linux distributions and
macOS via Homebrew.
Note
For Windows, it is recommended to instead build the libraries from source, for maximum compatibility with the local toolchain. Building from source can be automated by using a from-source library package management tool such as Conan or vcpkg (See: Cross Platform Installs Using Library Package Managers).
Warning
If you install and use prebuilt binaries from a third-party packager, it is possible that it lags behind the version of the libraries described in these documentation pages (1.28). Note the version that you install and keep it in mind when reading these pages.
For the most up-to-date versions of the C driver libraries, prefer to instead build from source.
Tip
See also:
For a listing and common reference on available packages, refer to Package Installation Reference.
Cross Platform Installs Using Library Package Managers
Various library package managers offer libbson
and libmongoc
as installable
packages, including Conan and vcpkg.
This section will detail how to install using those tools.
Installing using vcpkg
Note
This page will not detail how to get started using vcpkg. For that, refer to Get started with vcpkg
In vcpkg manifest mode, add the
desired libraries to your project's vcpkg.json
manifest file:
{ // ... "dependencies": [ // ... "mongo-c-driver" ] }
When you build a CMake project with vcpkg integration and have a
vcpkg.json
manifest file, vcpkg will automatically install the project's
dependencies before proceeding with the configuration phase, so no
additional manual work is required.
In vcpkg classic mode,
libbson
and libmongoc
can be installed through the names libbson
and
mongo-c-driver
, respectively:
$ vcpkg install mongo-c-driver
(Installing mongo-c-driver
will transitively install libbson
as well.)
When the libmongoc
and libbson
packages are installed and vcpkg has been
properly integrated into your build system, the desired libraries will be
available for import.
With CMake, the standard config-file package will be available, as well as the
generated IMPORTED
targets:
find_package(mongoc-1.0 CONFIG REQUIRED) target_link_libraries(my-application PRIVATE $<IF:$<TARGET_EXISTS:mongo::mongoc_shared>,mongo::mongoc_shared,mongo::mongoc_static>)
Note
The large $<IF:$<TARGET_EXISTS...>:...>
generator expression
can be used to switch the link type of libmongoc
based on whichever form
is available from the find_package()
command. libmongoc
supports building
with both dynamic and static library types, but vcpkg will only install one
of the two library types at a time.
Configuring a CMake project with vcpkg integration is a matter of setting the CMake toolchain file at the initial configure command:
$ cmake -S . -B _build -D CMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake
Installing in Linux
The names and process of installing libbson
and libmongoc
varies between
distributions, but generally follows a similar pattern.
The following Linux distributions provide libbson
and libmongoc
packages:
Fedora via
dnf
RedHat Enterprise Linux (RHEL) 7 and Newer and distributions based on RHEL 7 or newer, including CentOS, Rocky Linux, and AlmaLinux, via
yum
/dnf
and EPEL.Debian and Debian-based distributions, including Ubuntu and Ubuntu derivatives, via APT.
Tip
See also:
For a list of available packages and package options, see: Package Installation Reference.
RedHat-based Systems
In RedHat-based Linux distributions, including Fedora, CentOS, Rocky Linux, and AlmaLinux, the C driver libraries can be installed with Yum/DNF.
Note
For Fedora and enterprise Linux of version 8 or greater, it is recommended to
use the dnf
command in place of any yum
command.
Important
Except for Fedora:
The C driver libraries are only available in version 7 and newer of the
respective enterprise Linux distributions. However, the C driver libraries
are not available in the default repositories, but can be obtained by enabling
the EPEL repositories. This can be done by installing the epel-release
package:
# yum install epel-release
epel-release
must be installed before attempting to install the C driver
libraries (i.e. one cannot install them both in a single yum install
command).
To install libbson
only, install the libbson-devel
package:
# yum install libbson-devel
To install the full C database driver (libmongoc
), install
mongo-c-driver-devel
:
## (This package will transitively install libbson-devel) # yum install mongo-c-driver-devel
To check which version is available, see https://packages.fedoraproject.org/pkgs/mongo-c-driver/mongo-c-driver-devel.
The development packages (ending in -devel
) include files required to build applications using
libbson
and libmongoc
. To only install the libraries without development files, install the
libbson
or mongo-c-driver-libs
packages.
Debian-based Systems
In Debian-based Linux distributions, including Ubuntu and Ubuntu derivatives,
libbson
and libmongoc
are available in the distribution repositories via
APT, and can be installed as libbson-dev
and libmongoc-dev
, respectively:
## Update repository information, if necessary: # apt update
To install only libbson
:
# apt install libbson-dev
To install libmongoc
(which will also install libbson
):
# apt install libmongoc-dev
To check which version is available, run apt-cache policy libmongoc-dev
.
The development packages (ending in -dev
) include files required to build applications using
libbson
and libmongoc
. To only install the libraries without development files, install
the libbson-1.0-0
or libmongoc-1.0-0
packages.
Installing on macOS with Homebrew
If you are using a macOS system, the C driver libraries (including both
libmongoc
and libbson
) may be installed using the Homebrew
package manager with the following command:
$ brew install mongo-c-driver
Note
Homebrew does not provide separate packages for libbson
and libmongoc
.
Tip
The Homebrew package manager is not installed by default on macOS. For information on installing Homebrew, refer to the Homebrew installation documentation page.