1MONGOC_INSTALLING(3) MongoDB C Driver MONGOC_INSTALLING(3)
2
3
4
6 mongoc_installing - Installing the MongoDB C Driver (libmongoc) and
7 BSON library (libbson)
8
9 The following guide will step you through the process of downloading,
10 building, and installing the current release of the MongoDB C Driver
11 (libmongoc) and BSON library (libbson).
12
14 The MongoDB C Driver is continuously tested on variety of platforms
15 including:
16
17 · Archlinux
18
19 · Debian 8.1
20
21 · macOS 10.10
22
23 · Microsoft Windows Server 2008
24
25 · RHEL 7.0, 7.1, 7.2
26
27 · SUSE 12
28
29 · Ubuntu 12.04, 14.04, 16.04
30
31 · Clang 3.4, 3.5, 3.7, 3.8
32
33 · GCC 4.6, 4.8, 4.9, 5.3
34
35 · MinGW-W64
36
37 · Visual Studio 2010, 2013, 2015
38
39 · x86, x86_64, ARM (aarch64), Power8 (ppc64le), zSeries (s390x)
40
42 Several Linux distributions provide packages for libmongoc and its
43 dependencies. One advantage of installing libmongoc with a package man‐
44 ager is that its dependencies (including libbson) will be installed
45 automatically.
46
47 The libmongoc package is available on recent versions of Debian and
48 Ubuntu.
49
50 $ apt-get install libmongoc-1.0-0
51
52 On Fedora, a mongo-c-driver package is available in the default reposi‐
53 tories and can be installed with:
54
55 $ dnf install mongo-c-driver
56
57 On recent Red Hat systems, such as CentOS and RHEL 7, a mongo-c-driver
58 package is available in the EPEL repository. To check which version is
59 available, see https://apps.fedoraproject.org/packages/mongo-c-driver.
60 The package can be installed with:
61
62 $ yum install mongo-c-driver
63
65 The libbson package is available on recent versions of Debian and
66 Ubuntu. If you have installed libmongoc, then libbson will have already
67 been installed as a dependency. It is also possible to install libbson
68 without libmongoc.
69
70 $ apt-get install libbson-1.0
71
72 On Fedora, a libbson package is available in the default repositories
73 and can be installed with:
74
75 $ dnf install libbson
76
77 On recent Red Hat systems, such as CentOS and RHEL 7, a libbson package
78 is available in the EPEL repository. To check which version is avail‐
79 able, see https://apps.fedoraproject.org/packages/libbson. The package
80 can be installed with:
81
82 $ yum install libbson
83
85 Prerequisites for libmongoc
86 OpenSSL is required for authentication or for SSL connections to Mon‐
87 goDB. Kerberos or LDAP support requires Cyrus SASL.
88
89 To install all optional dependencies on RedHat / Fedora:
90
91 $ sudo yum install cmake openssl-devel cyrus-sasl-devel
92
93 On Debian / Ubuntu:
94
95 $ sudo apt-get install cmake libssl-dev libsasl2-dev
96
97 On FreeBSD:
98
99 $ su -c 'pkg install cmake openssl cyrus-sasl'
100
101 Prerequisites for libbson
102 The only prerequisite for building libbson is cmake. The command lines
103 above can be adjusted to install only cmake.
104
105 Building from a release tarball
106 Unless you intend to contribute to mongo-c-driver and/or libbson, you
107 will want to build from a release tarball.
108
109 The most recent release of libmongoc and libbson, both of which are
110 included in mongo-c-driver, is 1.13.1 and can be downloaded here. The
111 instructions in this document utilize cmake's out-of-source build fea‐
112 ture to keep build artifacts separate from source files.
113
114 The following snippet will download and extract the driver, and config‐
115 ure it:
116
117 $ wget https://github.com/mongodb/mongo-c-driver/releases/download/1.13.1/mongo-c-driver-1.13.1.tar.gz
118 $ tar xzf mongo-c-driver-1.13.1.tar.gz
119 $ cd mongo-c-driver-1.13.1
120 $ mkdir cmake-build
121 $ cd cmake-build
122 $ cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF ..
123
124 The -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF option is recommended, see
125 init-cleanup. Another useful cmake option is -DCMAKE_BUILD_TYPE=Release
126 for a release optimized build and -DCMAKE_BUILD_TYPE=Debug for a debug
127 build. For a list of all configure options, run cmake -L ...
128
129 If cmake completed successfully, you will see a considerable amount of
130 output describing your build configuration. The final line of output
131 should look something like this:
132
133 -- Build files have been written to: /home/user/mongo-c-driver-1.13.1/cmake-build
134
135 If cmake concludes with anything different, then there is likely an
136 error or some other problem with the build. Review the output to iden‐
137 tify and correct the problem.
138
139 mongo-c-driver contains a copy of libbson, in case your system does not
140 already have libbson installed. The build will detect if libbson is not
141 installed and use the bundled libbson.
142
143 Additionally, it is possible to build only libbson by setting the -DEN‐
144 ABLE_MONGOC=OFF option:
145
146 $ cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF -DENABLE_MONGOC=OFF ..
147
148 A build configuration description similar to the one above will be dis‐
149 played, though with fewer entries. Once the configuration is complete,
150 the selected items can be built and installed with these commands:
151
152 $ make
153 $ sudo make install
154
155 There are two ways to uninstall the components that have been
156 installed. The first is to invoke the uninstall program directly. On
157 Linux/Unix:
158
159 $ sudo /usr/local/share/mongo-c-driver/uninstall.sh
160
161 On Windows:
162
163 C:\Users\user> C:\mongo-c-driver\share\mongo-c-driver\uninstall.bat
164
165 The second way to uninstall is from within the build directory, assum‐
166 ing that it is in the exact same state as when the install command was
167 invoked:
168
169 $ sudo make uninstall
170
171 The second approach simply invokes the uninstall program referenced in
172 the first approach.
173
174 Building from git
175 Clone the repository and build the current master or a particular
176 release tag:
177
178 $ git clone https://github.com/mongodb/mongo-c-driver.git
179 $ cd mongo-c-driver
180 $ git checkout x.y.z # To build a particular release
181 $ mkdir cmake-build
182 $ cd cmake-build
183 $ cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF ..
184 $ make
185 $ sudo make install
186
187 Generating the documentation
188 Install Sphinx, then:
189
190 $ cmake -DENABLE_MAN_PAGES=ON -DENABLE_HTML_DOCS=ON ..
191 $ make mongoc-doc
192
193 To build only the libbson documentation:
194
195 $ cmake -DENABLE_MAN_PAGES=ON -DENABLE_HTML_DOCS=ON ..
196 $ make bson-doc
197
198 The -DENABLE_MAN_PAGES=ON and -DENABLE_HTML_DOCS=ON can also be added
199 as options to a normal build from a release tarball or from git so that
200 the documentation is built at the same time as other components.
201
203 Install the XCode Command Line Tools:
204
205 $ xcode-select --install
206
207 The cmake utility is also required. First install Homebrew according to
208 its instructions, then:
209
210 $ brew install cmake
211
212 Download the latest release tarball:
213
214 $ curl -LO https://github.com/mongodb/mongo-c-driver/releases/download/1.13.1/mongo-c-driver-1.13.1.tar.gz
215 $ tar xzf mongo-c-driver-1.13.1.tar.gz
216 $ cd mongo-c-driver-1.13.1
217
218 Build and install the driver:
219
220 $ mkdir cmake-build
221 $ cd cmake-build
222 $ cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF ..
223
224 All of the same variations described above (e.g., building only libb‐
225 son, building documentation, etc.) are available when building on mac‐
226 OS.
227
229 Building on Windows requires Windows Vista or newer and Visual Studio
230 2010 or newer. Additionally, cmake is required to generate Visual Stu‐
231 dio project files.
232
233 Let's start by generating Visual Studio project files. The following
234 assumes we are compiling for 64-bit Windows using Visual Studio 2015
235 Express, which can be freely downloaded from Microsoft. We will be uti‐
236 lizing cmake's out-of-source build feature to keep build artifacts sep‐
237 arate from source files.
238
239 cd mongo-c-driver-1.13.1
240 mkdir cmake-build
241 cd cmake-build
242 cmake -G "Visual Studio 14 2015 Win64" \
243 "-DCMAKE_INSTALL_PREFIX=C:\mongo-c-driver" \
244 "-DCMAKE_PREFIX_PATH=C:\mongo-c-driver" \
245 ..
246
247 (Run cmake -LH .. for a list of other options.)
248
249 Now that we have project files generated, we can either open the
250 project in Visual Studio or compile from the command line. Let's build
251 using the command line program msbuild.exe:
252
253 msbuild.exe /p:Configuration=RelWithDebInfo ALL_BUILD.vcxproj
254
255 Visual Studio's default build type is Debug, but we recommend a release
256 build with debug info for production use. Now that libmongoc and libb‐
257 son are compiled, let's install them using msbuild. It will be
258 installed to the path specified by CMAKE_INSTALL_PREFIX.
259
260 msbuild.exe INSTALL.vcxproj
261
262 You should now see libmongoc and libbson installed in C:\mongo-c-driver
263
264 To use the driver libraries in your program, see visual-studio-guide.
265
267 Install MSYS2 from msys2.github.io. Choose the x86_64 version, not
268 i686.
269
270 Open c:\msys64\ming64_shell.bat (not the msys2_shell). Install depen‐
271 dencies:
272
273 pacman --noconfirm -Syu
274 pacman --noconfirm -S mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake
275 pacman --noconfirm -S mingw-w64-x86_64-extra-cmake-modules make tar
276 pacman --noconfirm -S mingw64/mingw-w64-x86_64-cyrus-sasl
277
278 Download and untar the latest tarball, enter its directory, and build
279 with CMake:
280
281 CC=/mingw64/bin/gcc.exe /mingw64/bin/cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX="C:/mongo-c-driver" ..
282 make
283
285 MongoDB, Inc
286
288 2017-present, MongoDB, Inc
289
290
291
292
2931.13.1 Jan 24, 2019 MONGOC_INSTALLING(3)